Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何自定义tableView剖面视图-iPhone_Iphone_Xcode_Uitableview - Fatal编程技术网

如何自定义tableView剖面视图-iPhone

如何自定义tableView剖面视图-iPhone,iphone,xcode,uitableview,Iphone,Xcode,Uitableview,我知道如何自定义tableViewCell 我看到许多应用程序自定义tableView单元格 类似地,我想自定义TableView节头 假设-节名应使用不同的字体,具有不同的背景图像等 怎么可能 我应该用哪种方法实现代码?而不是使用普通方法 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 您要实现此功能: - (UIView *)tableView:(UITa

我知道如何自定义tableViewCell

我看到许多应用程序自定义tableView单元格

类似地,我想自定义TableView节头

假设-节名应使用不同的字体,具有不同的背景图像等

怎么可能


我应该用哪种方法实现代码?

而不是使用普通方法

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
您要实现此功能:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
如您所见,第二个返回的是UIView,而不仅仅是文本字符串。因此,您可以自定义自己的视图(带有标签等)并返回它

下面是一个如何实现的示例(将在上述方法中实现):


希望这有帮助

例如,如果您的表有两个节,您将如何引用第二个表节,以便节头1的headerLabel.text与节头2的headerLabel.text不同?通过传递到方法中的整数。如果我只希望节头=1,而不希望节头=0,该怎么办?我对这个问题有一个问题…@jsetting32:你找到解决方案了吗?我不记得很久以前了,但我想你可以简单地返回一个空视图,对于indexath.section==0,对于indexPath.section==1,返回自定义视图
// create the parent view that will hold header Label
UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] autorelease];

// create image object
UIImage *myImage = [UIImage imageNamed:@"someimage.png"];;

// create the label objects
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.frame = CGRectMake(70,18,200,20);
headerLabel.text =  @"Some Text";
headerLabel.textColor = [UIColor redColor];

UILabel *detailLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.textColor = [UIColor darkGrayColor];
detailLabel.text = @"Some detail text";
detailLabel.font = [UIFont systemFontOfSize:12];
detailLabel.frame = CGRectMake(70,33,230,25);

// create the imageView with the image in it
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,50,50);

[customView addSubview:imageView];
[customView addSubview:headerLabel];
[customView addSubview:detailLabel];

return customView;