2013-01-24 52 views
0

我已經建立了使用自定義的細胞作爲這樣的實現代碼如下: -當按下按鈕在原型細胞更改標籤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{SWHNearYouCell *cell = (SWHNearYouCell *)[tableView 
            dequeueReusableCellWithIdentifier:@"NearYouCell"]; 

SWHNearYou *aPointer = [self.thingsNearYou objectAtIndex:indexPath.row]; 
cell.customNearYouLabel.text = aPointer.restrauntsNearYou; 
return cell; 
} 

我想在按下一個按鈕來改變customNearYouLabel的文本,但工作如何在我的-IBAction方法中獲取指向單元格的指針。

感謝

回答

0

您可以只處理在您的tableView:didSelectRowAtIndexPath:方法通過抓取細胞。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.customNearYouLabel.text = @"New Text"; 
} 
+0

正在尋找在酒吧按下按鈕 - 雖然 –

+0

這改變了一切。你只需要在你點擊按鈕時調整你的數據,然後在表上調用'reloadData'。當按鈕被按下時,可能只是有一個BOOL。然後在你的'cellForRowAtIndexPath'中檢查BOOL。 –

0

我認爲按鈕不在表格單元格上?

如果是這樣,您只需要更新self.thingsNearYou陣列中的相關值。

如果您然後調用[tableView reloadData],那麼該表將重新加載它的數據,並且customNearYouLabel的文本將改變。

0

的工作了 - 自我實現代碼如下之前添加需要

-(IBAction)cancel:(id)sender{ 


    SWHNearYouCell *cell = (SWHNearYouCell *)[self.tableView 
              dequeueReusableCellWithIdentifier:@"NearYouCell"]; 

cell.customNearYouLabel.text = @"New Text"; 

NSLog(@"This is it: %@",cell.customNearYouLabel.text); 

} 

我需要多花點時間在上面爲[self.tableView reloadData];不會更新表格,但我認爲應該更容易解決。

+0

這是非常非常錯誤的。你不應該這樣訪問單元格。檢查我的評論。 –