我在UITableView
中多行選擇的初始問題已在this問題中得到解答。但是,答案讓我無法獨立,因爲我對Objective C和iOS開發非常陌生。Objective-C:如何聲明/定義在tableView上使用的方法
繼daxnitro的回答,我想實現的代碼,他/她建議:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView indexPathIsSelected:indexPath]) {
[tableView removeIndexPathFromSelection:indexPath];
} else {
[tableView addIndexPathToSelection:indexPath];
}
// Update the cell's appearance somewhere here
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
我還是需要的方法,我想我能爲indexPathIsSelected
做到這一點(例如)是這樣的:
@interface MyTableViewController()
- (BOOL)indexPathIsSelected:(NSIndexPath *)indexPath;
@end
@implementation MyTableViewController
// ...
- (BOOL)indexPathIsSelected:(NSIndexPath *)indexPath
{
BOOL bIsSelected = NO;
// ...
return bIsSelected;
}
@end
但這並不奏效。錯誤消息是:'UITableView'沒有可見的@interface聲明選擇器'indexPathIsSelected:'注意:如果我在.h文件的接口中聲明該方法,則會發生同樣的情況。
現在,讓我感到困惑的是:[tableView indexPathIsSelected:indexPath]
以某種方式在tableView
對象上調用,我甚至不知道爲什麼。我的方法聲明/定義中是否需要考慮這些內容?我現在覺得很愚蠢,甚至連看到它的調用都寫不出方法。
如何正確定義和聲明方法indexPathIsSelected
,以便我可以正確使用它?
請參閱:http://stackoverflow.com/questions/5375122/how-to-select-multiple-rows-in-uitableview – Mrunal 2013-03-15 16:12:34
@mrunal海報有一個具體問題與他目前的做法,完全重新做它用另一種方法是矯枉過正。我認爲這是一個單線修復。 – wilsonmichaelpatrick 2013-03-15 16:14:50