Nik*_*iko 3 xcode static cell tableview ios
我有一个静态tableView与一些自定义单元格.我不想做的是以编程方式更改节标题.据我所知,因为单元格是静态的,我不能使用像cellForRowAtIndexPath这样的方法,所以我的问题是,它是否可能像它一样改变它们.
self.tableView.section1.text = @"title1"; // something like this?
Run Code Online (Sandbox Code Playgroud)
我试图创建该部分的IBOutlet但我收到以下错误:
Unknown type name 'UITableViewSection': did you mean 'UITableViewStyle?'
Run Code Online (Sandbox Code Playgroud)
我能做的是编辑单元格的内容,但不是标题.
谢谢!
使用viewForHeaderInSection方法.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *label1 = [[UILabel alloc] init];
label1.frame = CGRectMake(0, 0, 190, 20);
label1.textColor = [UIColor blackColor];
// label1.font = [UIFont fontWithName:@"Helvetica Bold" size:16];
[label1 setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14]];
label1.textAlignment = UITextAlignmentCenter;
label1.text =[NSString stringWithFormat:@"Title %d",section];
// If your title are inside an Array then Use Below Code
label1.text =[titleArray objectAtindex:section];
label1.textColor = [UIColor whiteColor];
label1.backgroundColor = [UIColor clearColor];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[view addSubview:label1];
view.backgroundColor = [UIColor orangeColor];
return view;
}
Run Code Online (Sandbox Code Playgroud)
如果你想使用titleForHeaderInSection然后使用下面的代码.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"Title %d",section];
// If your title are inside an Array then Use Below Code
return [titleArray objectAtindex:section];
}
Run Code Online (Sandbox Code Playgroud)