我需要某人帮忙声明以下数组: -
self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil];
于: -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
cell.textLabel.text = @"cell text";
cell.imageView.image = [UIImage imageNamed:[tablePicture objectAtIndex:indexPath.row]];
return cell;
}
如何在.h和.m文件中应用它?我对此很新。
提前致谢:)
PS。当我申请以下内容时,我会重复“pic1.png”而没有数组。
{
self = [super init];
if (self) {
// Custom initialization
self.tableData = [NSArray arrayWithObjects:@"Region", @"Subregion", @"Country", @"County", @"City", @"District", nil];
self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil];
CGRect frame = self.view.bounds;
frame.size.height -= 100;
self.tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];
[self.tableView setScrollEnabled:NO];
[self.view addSubview:self.tableView];
}
return self;
}
答案 0 :(得分:1)
·H
@property (nonatomic, retain) NSArray *tablePicture;
的.m
@synthesize tablePicture;
...
-(void)dealloc{
[tablePicture release];
[super dealloc];
}
答案 1 :(得分:0)
在View Controller的.h文件中声明数组的属性:
@property (nonatomic, retain) NSArray *tablePicture;
在View Controller的.m文件的ViewDidLoad
方法中设置数组属性的值:
@synthesize tablePicture;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil];
}
答案 2 :(得分:0)
听起来问题可能在数组初始化之外。
为什么不尝试添加:
NSLog(@"%@",self.tablePicture);
行后
"self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil];"