Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Iphone 如何将图像和标题添加到表视图的标题_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 如何将图像和标题添加到表视图的标题

Iphone 如何将图像和标题添加到表视图的标题,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,在表视图中,我创建了标题 在tableView的标题中设置图像或标题的正确方法是什么?我需要做什么 短暂性脑缺血发作 通过此设置,您可以为tableview节标题设置图像背景 方法中的 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 您需要创建一个UIView并添加其他视图,如UIImageView(用于图像)、UILabel(用于标题),最后返回UIView。请使

在表视图中,我创建了标题

在tableView的标题中设置图像或标题的正确方法是什么?我需要做什么

短暂性脑缺血发作

通过此设置,您可以为tableview节标题设置图像背景

方法中的

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
您需要创建一个
UIView
并添加其他视图,如
UIImageView
(用于图像)、
UILabel
(用于标题),最后返回
UIView

请使用此代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

   UIImage *myImage = [UIImage imageNamed:@"loginHeader.png"];
   UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
   imageView.frame = CGRectMake(10,10,300,100);

   return imageView;

}
-(void)viewDidLoad
{
   [super viewDidLoad];
   self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
}
我使用了以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

   UIImage *myImage = [UIImage imageNamed:@"loginHeader.png"];
   UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
   imageView.frame = CGRectMake(10,10,300,100);

   return imageView;

}
-(void)viewDidLoad
{
   [super viewDidLoad];
   self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
}

您指的是tableView中的节标题还是TableViewImage顶部的公共标题,现在正在添加,但它已扩展为完整标题,我们是否需要为此设置高度和宽度?创建UIImageView时,请使用所需的矩形初始化。例如UIImageView*imgView=[UIImageView alloc]initWithFrame:CGRectMake(CGFloat x,CGFloat y,CGFloat width,CGFloat height)];