我有一个场景,我的表中包含产品列表。此列表有一个footerView,其中一个按钮添加到footerView。当我打开已创建的产品列表时,我能够看到/滚动完整的footerView以及按钮。但是当我创建&amp ;;时,我无法在footerView中看到完整的按钮。首次保存产品列表。
我正在使用以下代码:
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE_WIDTH, 44)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10, 0, SCREEN_SIZE_WIDTH - 20, 44);
[footerView addSubview:button];
self.tableView.tableFooterView = footerView;
[self.tableView setTableFooterView:footerView];//Tried this one too
请帮我在footerView中显示/滚动按钮。谢谢!
答案 0 :(得分:0)
使用此代码,它对我来说很好:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(array.count>1){
if(indexPath.row == array.count-1){
[self setupTableViewFooter];
}
}
}
- (void)setupTableViewFooter
{
// set up label
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
footerView.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:Font_MuseoSans size:14];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.textColor = [UIColor darkGrayColor];
label.text = @"Loading";
self.footerLabel = label;
CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size];
[footerView addSubview:self.footerLabel];
// set up activity indicator
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.hidesWhenStopped = YES;
activityIndicatorView.color = [UIColor blackColor];
self.activityIndicator = activityIndicatorView;
[self.activityIndicator startAnimating];
[footerView addSubview:self.activityIndicator];
CGRect footerFrame = footerView.frame;
label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2
, (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height);
self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2
, activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
self.tableView.tableFooterView = footerView;
}