我不知道爲什麼發生這種情況,但我得到這個錯誤:在單元格中處理UIImageView觸摸時出錯?
-[__NSArrayM section]: unrecognized selector sent to instance 0x7e53b70 2012-01-07 15:35:44.108 Timely1[51661:15203] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM section]: unrecognized selector sent to instance 0x7e53b70'
時handleTouch
被激活。這裏是我添加圖片和點擊手勢的代碼。
[cell.imageView setUserInteractionEnabled:YES];
[cell.imageView setImage:[UIImage imageNamed:@"checkbox.PNG"]];
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];
[tapped release];
,然後我處理的觸摸代碼:
-(void)handleTouch:(UITapGestureRecognizer *)gesture
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.imageView setImage:[UIImage imageNamed:@"checkbox_checked.PNG"]];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];
}
UPDATE:怎麼樣,如果我想取消它(如翻轉它)沒有任何人知道該怎麼做?
在我看來,你以前遇到的問題在於 - NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];相反,你需要使用NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] -1 inSection:1]; – rishi 2012-01-07 16:59:43
是的,但是你知道如何修復'[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];'因爲我知道那是問題所在,但是如果我想再次加載一個單元格,不再使用該行。 – Souljacker 2012-01-07 17:15:41
你是否在數組中傳遞NSIndexPath的對象? – rishi 2012-01-07 17:17:35