【发布时间】:2014-02-24 09:00:04
【问题描述】:
我的 UITableView 中有几个部分,其中有时可以有 0 行。如果 numberOfRowsInSection 等于 0,我如何删除节标题?
这是我的部分代码:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 22)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, tableView.frame.size.width, 22)];
[label setFont:[UIFont boldSystemFontOfSize:14]];
[label setTextColor:[UIColor whiteColor]];
NSString *string =[[theLeagueArray objectAtIndex:section] objectForKey:@"league"];
[label setText:string];
[view addSubview:label];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 22)];
[imgView setImage:[UIImage imageNamed:[[theLeagueArray objectAtIndex:section] objectForKey:@"img"]]];
[view addSubview:imgView];
[view setBackgroundColor:[UIColor colorWithRed:13/255.0f green:78/255.0f blue:102/255.0f alpha:1.0f]];
return view;
}
【问题讨论】:
-
将您的行数代码放在此处
-
您可以使用 UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;并在数据发生任何变化后使用 reload tableview
标签: ios objective-c uitableview