UITableView tableFooterView没有出现

Arm*_*and 5 iphone uitableview ios

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

我如何添加我的 tableFooterView

我在重新加载数据后添加了tableFooterView一个connectionDidFinishLoading方法tableview.

所以我做的是

[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];
Run Code Online (Sandbox Code Playgroud)

页脚视图高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

- (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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Adi*_*mro 7

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

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

所以默认propertynil.这就是为什么你不能添加另一个UIView为零UIView.你应该做这样的事情:

controls.tableFooterView = myFooterView;
Run Code Online (Sandbox Code Playgroud)