在commitEditingStyle tableView方法中,".row“属性在NSIndexPath上不起作用。有什么想法吗?
这就是调用
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSLog(@" Delete button pushed. IndexPath:%@",indexPath);
}}在表的第三行按下delete按钮时,日志消息为:
‘删除按钮已按下。IndexPath: 2索引0,2’
如果我将日志消息更改为:
NSLog(@" Delete button pushed. IndexPath.row:%@",indexPath.row);我得到一个编译错误。怎么回事?我以为NSIndexPath有一个'row‘属性。显然,当我检查indexPath时,它就在那里。
库尔特
发布于 2011-10-31 02:17:52
问题出在您的格式说明符。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.https://stackoverflow.com/questions/7946733
复制相似问题