2011-10-30 45 views
1

在commitEditingStyle tableView方法中,「.row」屬性在NSIndexPath上不起作用。有任何想法嗎?commitEditingStyle中的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有'row'屬性。顯然,當我檢查indexPath時,它就在那裏。

Kurt

回答

2

問題出在您的格式說明符。 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. 
+0

這很好記,Objective-C ...謝謝。 – Kurt