2015-07-10 30 views
-1

我想要具有不同名稱的表格單元格,但到目前爲止他們都具有文本'1'。 如何使單元格具有唯一的名稱,如tableData數組中所述?obj c表中不同的表格單元格名稱

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // self.clearsSelectionOnViewWillAppear = NO;  
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    tableData = [NSMutableArray arrayWithObjects:@"1", @"2", @"333", nil]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { 
    return [tableData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subTable"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CELL"]; 
    } 
    cell.textLabel.text = [tableData objectAtIndex:0]; 
    return cell; 
} 

聽說我可能需要使用'forIndex'或'indexPath'或其他一些方法嗎?

回答

2

改變這一行:

cell.textLabel.text = [tableData objectAtIndex:0]; 

這樣:

cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; 

不粗魯,只是一個想法:如果這不是明擺着給你,你應該先從一些入門級的水平教程。

相關問題