2012-02-07 69 views
-4

我需要某人的帮助声明如下数组: -如何声明数组

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; 
} 
+2

等待之后,有什么问题吗? – 2012-02-07 21:26:08

+0

数组看起来不错,请检查下面的.h&.m下面的@beryllium答案。但是,你的意思是没有细胞被输​​出?如果是的话,你已经实现了UITableView数据源,并有这些方法: - numberOfSectionsInTableView: - tableView:numberOfRowsInSection:? – jodm 2012-02-07 21:33:28

回答

1

.H

@property (nonatomic, retain) NSArray *tablePicture; 

.M

@synthesize tablePicture; 

... 

-(void)dealloc{ 
    [tablePicture release]; 
    [super dealloc]; 
} 
+0

这是伟大的,但我似乎只获得第一个“pic1.png”为每个相应的表单元格重复 – CraigBellamy 2012-02-07 21:50:32

+0

感谢它的工作原理:) – CraigBellamy 2012-02-07 22:05:09

0

声明您数组的属性在视图控制器的.h文件中:

@property (nonatomic, retain) NSArray *tablePicture; 

设置的值你的数组属性在您的视图控制器的.m文件中方法:

@synthesize tablePicture; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil]; 
} 
+0

感谢它的一半作品,但不重复只是“pic1.png”重复自己。 ..见上面的编辑 – CraigBellamy 2012-02-07 21:56:43

+0

你的tableView中有多个部分吗?如果对'numberOfSectionsInTableView:'和'numberOfRowsInSection:' – jonkroll 2012-02-07 22:06:52

+0

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {0}返回self.tableData.count; (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { } return 1; } – CraigBellamy 2012-02-07 22:36:34

0

听起来这个问题可能是你的数组初始化之外。

你为什么不尝试添加:

NSLog(@"%@",self.tablePicture); 

"self.tablePicture = [NSArray arrayWithObjects:@"pic1.png", @"pic2.png", @"Country.png", nil];" 
+0

我试过了,但还是只有pic1.png重复自己:( – CraigBellamy 2012-02-07 22:27:59