2013-01-24 104 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

这是非常非常错误的。你不应该这样访问单元格。检查我的评论。 –