我目前有一個UIAlertview顯示分組表視圖,並花了整整一週得到它的工作恰到好處,我離開本應該是最簡單的部分,直到最後,添加配件。我想要的只是當它被點擊時將該行顯示爲選中狀態。這聽起來很簡單,乍一看工作正常。如果我在0,0處點擊單元格,它會被打勾但是,如果我然後向下滾動,我還會以2,1被打勾並且3,6(並且0,0會再次未打開)結束。我查看了This Question並在另一個分組表上測試了它們的代碼,它工作正常,但對我的警報表沒有影響。奇怪的分組tableview配件問題
這是我使用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
的代碼,我看沒辦法,這可以修改多個小區。我在那裏設置了一箇中斷點,並且每次點擊都只被稱爲一次。
Cellforrowatindex方法:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
NSArray *listData =[self.data objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger Row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:Row];
return cell;
}
感謝。
請同時分享你的'-tableview:cellForRowAtIndexPath:'方法,因爲它會產生新的行。 (新增功能如下:屏幕新增功能,表格中不新增功能) – mvds 2011-03-18 21:41:29
添加了所需的代碼。雖然我這樣做,我想我找到了問題。 'dequeueReusableCellWithIdentifier'是否可能重複使用附件中的單元格?如果是這樣,我怎麼能使附件添加棒滾動滾動,我需要把它寫回到某個地方?謝謝 – Darc 2011-03-18 21:58:29
幹得好,沒錯,是你的問題。 SDK不會記住您的配件,因此您必須自己去做,例如使用數組或字典。 – mvds 2011-03-18 23:50:17