问题
Basically, I want to create a button underneath a grouped table view, like contacts.app has to delete contacts.
I can create the button fine, I'm just a bit puzzled as to how to decide where to put it.
I thought I could just do:
CGRect bounds = [[self tableView] bounds];
Then place the button based on that.
However, when accessing the size.height of bounds I get zero! Is there a dynamic way to retrieve the tableView's height that I could be missing?
Any help is greatly appreciated.
Rich
回答1:
You can create the size of your button like
CGRect buttonFrame = CGRectMake(0, 0, width, height);
Create the button with that frame, and then set the button as the tableView
's footer
myTableView.tableFooterView = myButton;
回答2:
You could try making a custom footer view with those buttons placed in that view by implementing these methods:
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
That should let you put any number of buttons on your table underneath the section you want.
回答3:
You can get the tablewViews heigh by looking at its frame
CGRect bounds= [[self tableView] frame];
float heigh= frame.size.height;
来源:https://stackoverflow.com/questions/1456668/uibutton-underneath-grouped-table-view