【问题标题】:UITableView tableFooterView not appearingUITableView tableFooterView 没有出现
【发布时间】:2012-04-01 19:33:02
【问题描述】:

我有一个UITableView,我在其中添加了一个tableFooterView,由于某种原因tableFooterView 没有出现?

我如何添加我的tableFooterView

在重新加载tableview 数据后,我在connectionDidFinishLoading 方法中添加了tableFooterView

所以我要做的是

[controls reloadData];

UIView *myFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
if(self.item.canRunOnDemand)
{
    UIButton *buttonRunWorkflow = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [buttonRunWorkflow addTarget:self action:@selector(runWorkflow:) forControlEvents:UIControlEventTouchDown];
    [buttonRunWorkflow setTitle:@"Run Now" forState:UIControlStateNormal];
    buttonRunWorkflow.frame = CGRectMake(15, 5, 290, 44); 
    buttonRunWorkflow.backgroundColor = [UIColor clearColor];
    [buttonRunWorkflow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myFooterView addSubview:buttonRunWorkflow];
}
if(item.canRunAlways)
{
    UILabel *canRunAlwaysLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 46, 100, 44)];
    canRunAlwaysLabel.backgroundColor = [UIColor clearColor];
    canRunAlwaysLabel.text = @"Run Always:";
    UISwitch *canRunAlways = [[UISwitch alloc] initWithFrame:CGRectMake(115, 56, 100, 44)];
    [canRunAlways addTarget:self action:@selector(canRunAlwaysChanged:) forControlEvents:UIControlEventValueChanged];
    [myFooterView addSubview:canRunAlways];
    [myFooterView addSubview:canRunAlwaysLabel];
    [canRunAlwaysLabel release];
    [canRunAlways release];
}

[myFooterView release];

[controls.tableFooterView addSubview:myFooterView];

页脚视图高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}

我也试过这个:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if(section == [[fields objectAtIndex:section] count] - 1)
    {
        return 100;
    }
    else {
        return 0;
    }
}
-(UIView*) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if(section == [[fields objectAtIndex:section] count] - 1)
    {
        UIView *myFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
        if(self.item.canRunOnDemand)
        {
            UIButton *buttonRunWorkflow = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [buttonRunWorkflow addTarget:self action:@selector(runWorkflow:) forControlEvents:UIControlEventTouchDown];
            [buttonRunWorkflow setTitle:@"Run Now" forState:UIControlStateNormal];
            buttonRunWorkflow.frame = CGRectMake(15, 5, 290, 44); 
            buttonRunWorkflow.backgroundColor = [UIColor clearColor];
            [buttonRunWorkflow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [myFooterView addSubview:buttonRunWorkflow];
        }
        if(item.canRunAlways)
        {
            UILabel *canRunAlwaysLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 46, 100, 44)];
            canRunAlwaysLabel.backgroundColor = [UIColor clearColor];
            canRunAlwaysLabel.text = @"Run Always:";
            UISwitch *canRunAlways = [[UISwitch alloc] initWithFrame:CGRectMake(115, 56, 100, 44)];
            [canRunAlways addTarget:self action:@selector(canRunAlwaysChanged:) forControlEvents:UIControlEventValueChanged];
            [myFooterView addSubview:canRunAlways];
            [myFooterView addSubview:canRunAlwaysLabel];
            [canRunAlwaysLabel release];
            [canRunAlways release];
        }
        return myFooterView;
    }
    else {
        return nil;
    }
}

【问题讨论】:

标签: iphone ios uitableview


【解决方案1】:

您是否要在表格视图中添加页脚视图? 如果您正在尝试在此方法中实现您的页脚视图

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

这可能对你有帮助。谢谢!!

【讨论】:

  • 但是当表为空时会发生什么?
  • 您在这里将“节页脚视图”与“表页脚视图”混淆了。 OP 要求后者。
  • 这是不正确的,节页脚将浮动在表格视图的顶部。
【解决方案2】:

通过查看UITableView.h 的头文件,我们看到属性tableFooterView 的声明如下:

@property(nonatomic,retain) UIView *tableFooterView; // accessory view below content. default is nil. not to be confused with section footer

所以默认的propertynil。这就是为什么您不能将另一个 UIView 添加到 nil UIView。 你应该这样做:

controls.tableFooterView = myFooterView;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 2018-10-26
    • 2017-01-18
    相关资源
    最近更新 更多