Uitableview 在TableView顶部添加图像
这可能是一个愚蠢的问题,但我真的已经为此挣扎了一分钟。我以编程方式创建了一个UITableView,使所有数据都能完美地流动,现在我只想在表的顶部添加一个静态图像,但似乎无法做到:-(我知道这可能是非常基本的,但我真的需要有人来帮我。所以通常你会创建一个UITableViewController,它将委托表如何工作(这是numberOfSectionsInTableView、numberOfSectionsInTableView等的位置。)方法是。要使单元格本身不同于默认值,您需要创建UITableViewCell的子类 customcell.hUitableview 在TableView顶部添加图像,uitableview,uiimageview,uiimage,Uitableview,Uiimageview,Uiimage,这可能是一个愚蠢的问题,但我真的已经为此挣扎了一分钟。我以编程方式创建了一个UITableView,使所有数据都能完美地流动,现在我只想在表的顶部添加一个静态图像,但似乎无法做到:-(我知道这可能是非常基本的,但我真的需要有人来帮我。所以通常你会创建一个UITableViewController,它将委托表如何工作(这是numberOfSectionsInTableView、numberOfSectionsInTableView等的位置。)方法是。要使单元格本身不同于默认值,您需要创建UITab
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell {
UILabel *primaryLabel;
UIImageView *myImageView;
}
@property (nonatomic, retain) UILabel *primaryLabel;
@property (nonatomic, retain) UIImageView *myImageView;
@end
然后返回UITableViewController:cellforrowatindexpath方法您应该分配自定义单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSInteger row = [indexPath row];
NSString *pathString= [snowBoardArray objectAtIndex:row];
NSString *string2= @"Cell";
pathString = [pathString stringByAppendingString:string2];
cell.primaryLabel.text=[snowBoardArray objectAtIndex:row];
NSString *filePath = [[NSBundle mainBundle] pathForResource:pathString ofType:@"png"];
UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:filePath];
cell.myImageView.image = theImage;
[theImage release];
return cell;
}
因此,通常您会创建一个UITableViewController,该控制器将委托表的工作方式(这是NumberOfSectionsTableView、NumberOfSectionsTableView等)方法。要使单元格本身不同于默认值,您需要创建UITableViewCell的子类 customcell.h
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell {
UILabel *primaryLabel;
UIImageView *myImageView;
}
@property (nonatomic, retain) UILabel *primaryLabel;
@property (nonatomic, retain) UIImageView *myImageView;
@end
然后返回UITableViewController:cellforrowatindexpath方法您应该分配自定义单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSInteger row = [indexPath row];
NSString *pathString= [snowBoardArray objectAtIndex:row];
NSString *string2= @"Cell";
pathString = [pathString stringByAppendingString:string2];
cell.primaryLabel.text=[snowBoardArray objectAtIndex:row];
NSString *filePath = [[NSBundle mainBundle] pathForResource:pathString ofType:@"png"];
UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:filePath];
cell.myImageView.image = theImage;
[theImage release];
return cell;
}
好吧,我最终用代码完成了它,它就在这里
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImage *myImage = [UIImage imageNamed:@"ranking_bar.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,320,30);
return imageView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
好吧,我最终用代码完成了它,它就在这里
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImage *myImage = [UIImage imageNamed:@"ranking_bar.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,320,30);
return imageView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
您好,谢谢您的回复,实际上我甚至不想在选项卡中显示图像,我的表从Y30px开始,因此我在顶部有一个空白区域,这是我想放置静态图像的地方。我想另一种放置方式是如何在坐标(0,0320,30)处添加图像?你试过只使用interface builder吗?我知道我的一个应用程序就是这样做的,我所做的只是放了一个UIPictureView(从内存中不记得图片视图的确切名称)我想我遗漏了一些东西,因为你听起来很精通,这是一个非常简单的方法。实际上,我通常用IB创建我的表格。这次我使用了一种不同的方法,只需要在我的视图上使用一个简单的UIImageView,我知道这听起来很疯狂,但我就是无法实现rk出于某种原因,也许可以和你一起睡个好觉,帮我做个小动作:-)是的,我实际上最后把它放在了标题上。谢谢你的帮助!你好,谢谢你的回复,实际上我甚至不想在标签中显示图像,我的表格从Y30px开始,所以我在顶部有一个空白,这是我想放置静态图像的地方。我想另一种放置方法是如何在坐标处添加图像(0,0320,30)?你试过只使用interface builder吗?我知道我的一个应用程序就是这样做的,我所做的只是放了一个UIPictureView(从内存中不记得图片视图的确切名称)我想我遗漏了一些东西,因为你听起来很精通,这是一个非常简单的方法。实际上,我通常用IB创建我的表格。这次我使用了一种不同的方法,只需要在我的视图上使用一个简单的UIImageView,我知道这听起来很疯狂,但我就是无法实现rk出于某种原因,可能会和do the trick for me一起睡个好觉:-)是的,我实际上把它放在了标题上。谢谢你的帮助!从实际答案复制粘贴从实际答案复制粘贴