【问题标题】:NSIndexPath in commitEditingStylecommitEditingStyle 中的 NSIndexPath
【发布时间】:2011-10-30 18:02:45
【问题描述】:

在 commitEditingStyle tableView 方法中,“.row”属性在 NSIndexPath 上不起作用。有什么想法吗?

电话来了

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete)
{
    NSLog(@" Delete button pushed. IndexPath:%@",indexPath);  
}}

当在表格的第三行按下删除按钮时,日志消息是:

'按下删除按钮。 IndexPath: 2 个索引 [0, 2]'

如果我将日志消息更改为:

NSLog(@" Delete button pushed. IndexPath.row:%@",indexPath.row);

我得到一个编译错误。是什么赋予了?我认为 NSIndexPath 有一个“行”属性。显然,当我检查 indexPath 时,它就在那里。

库尔特

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    问题在于您的格式说明符。 row 属性是整数类型,所以你需要使用%d 而不是%@

    .row 属性是UIKit 中定义的扩展类别的一部分。

    文档位于http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/Reference/Reference.html

    **row**
    
    An index number identifying a row in a section of a table view. (read-only)
    
    @property(readonly) NSUInteger row
    
    **Discussion**
    
    The section the row is in is identified by the value of section.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多