2010-07-06 15 views
0

如何查看在UITableView中選擇了哪個單元格?我只是想做一些簡單的事情,但我有點忘了該怎麼做。 :D無論如何,有人能幫助我嗎?我希望它是一個「如果」的聲明,如:如何判斷UITableView中的哪個單元?

if (/*The first cell got selected*/) { 
    self.label.text = @"Hello!" 
} 

有人可以填寫評論的空間嗎?

感謝

回答

1

想必你想要當用戶選擇他們這樣做呢?如果是這樣,則需要在您的表視圖代理中實施- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    if (indexPath.row == 0) { 
     UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; 
     cell.textLabel.text = @"Hello!"; 
    } 
    // ... other row selection logic 
} 
0
//table is a reference to your UITableView 
NSIndexPath* path = [table indexPathForSelectedRow]; 
if (path && path.row == 0) { 
    self.label.text = @"Hello!" 
} 

您還可以跟蹤更改所選狀態的UITableView的委託tableView:didDeselectRowAtIndexPath:方法

+0

表是什麼類?它沒有聲明。 – Nathan 2010-07-06 15:34:36

+0

你必須用你的表格出口替換'table'('self.tableView'可能工作取決於你的配置) – jrtc27 2010-07-06 16:51:37

相關問題