gpt4 book ai didi

iphone - UITableView tableFooterView 没有出现

转载 作者:可可西里 更新时间:2023-11-01 04:42:30 26 4
gpt4 key购买 nike

我有一个 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];

页脚 View 高度

- (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;
}
}

最佳答案

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

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

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

controls.tableFooterView = myFooterView;

关于iphone - UITableView tableFooterView 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9734191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com