Jon Jon - 1 year ago 93
Objective-C Question

How To Add UIButton Below UITableVIew?

My VC is a subclass of UITableView and I'm trying to add a UIButton at the button of the screen.

I know how to do this when my VC is a UIView with a UITableView object in it, but how can I add this button when I'm subclassing UITableView? I tried adding it in IB but it only lets me add it as the table's footer, which is only visible when the bottom of the table is scrolled to. Any ideas?

And also, how can I add an image behind the table while keeping the cells white? Its easy when the class is uiview, but not sure in this case.

Answer Source

Suggestion1 : You could have create a separate view which contains your UIButton and place below of the UITableView.

Remark : This is useful because when you scroll the tableView the default footer will be stick to bottom.

// position(change according to your position) of the bottom view 
                                             //and set the size of the button

UIView* bottomView = [[UIView alloc] initWithFrame:CGRectMake(5.0, 460.0, 300.0, 80.0)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

// position(change according to your position) of the button inside bottomView
                                             //and set the size of the button
myButton.frame = CGRectMake(20, 20, 200, 44);

[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
// add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[bottomView addSubview:myButton]; // add the button to bottom view
[self.view addSubView:bottomView]; //add bottom view main view

Suggestion2 : you can use viewForFooterInSection delegate method. where you can create a view and add the UILabel. viewForFooterInSection returns the UIView, which you can return your view which contains the UILabel

Remark : when you scroll the tableView the default footer will move along with your tableView


If your view is the subclass of UITableViewController, okay then change it to UIViewController and in your nib file Create a view and drag your tableView under the view and change the reference class to your UIViewController. Now create an IBOutlet of UITableView* myTableView and connect it to you nib file. you just need to change in your VC file for example self to [self.myTableView reloadData];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download