2012-01-07 52 views
1

我不知道爲什麼發生這種情況,但我得到這個錯誤:在單元格中處理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:怎麼樣,如果我想取消它(如翻轉它)沒有任何人知道該怎麼做?

+0

在我看來,你以前遇到的問題在於 - NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];相反,你需要使用NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] -1 inSection:1]; – rishi 2012-01-07 16:59:43

+0

是的,但是你知道如何修復'[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];'因爲我知道那是問題所在,但是如果我想再次加載一個單元格,不再使用該行。 – Souljacker 2012-01-07 17:15:41

+0

你是否在數組中傳遞NSIndexPath的對象? – rishi 2012-01-07 17:17:35

回答

2

在你handleTouch方法,我認爲你可以使用:

UIImageView *cellImageView=(UIImageView *)gesture.view; 
+0

謝謝你的工作。問題是'[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];',那是什麼給了錯誤。 – Souljacker 2012-01-07 15:43:02

+0

如果我想取消選中它(如切換),你知道該怎麼做嗎? – Souljacker 2012-01-07 15:50:06

+0

這讓我開始了,但我需要更多的數據,然後只是我的圖像的狀態,所以我決定創建一個類別擴展'@interface UITapGestureRecognizer(Utility)',添加一個額外的屬性'@property(nonatomic,strong)id userData;調用userData放置並稍後檢索我需要的參數。 – pulkitsinghal 2012-09-04 21:40:09

0

我已經決定了UIButton去爲我的複選框,並繼承我的UITableViewCell,似乎更容易和更合理的特別是與肘位。