我有一個UITableView
填充了27行。我正在嘗試更改所選單元格的accessoryType
。我在didSelectRowAtIndexPath:
委託方法中這樣做。didSelectRowAtIndexPath一次選擇多個行
我面臨的問題是,當選擇一行並更改單元格的accessoryType
時,該行的第11行也會被修改。
我試過打印[indexPath row]
的值,但它只顯示被選中的行而不是另一個。
我很困惑這樣的東西;請幫助我。
添加的代碼cellForRowAtIndexPath
方法
UITableViewCell *cell;
if ([indexPath row] == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"acell"];
}
else {
cell = [tableView dequeueReusableCellWithIdentifier:@"bcell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell == nil && [indexPath row] != 0) {
cell = [[[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:@"bcell"] autorelease];
}
else if(cell == nil && [indexPath row] == 0){
cell = [[[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:@"acell"] autorelease];
}
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
if ([indexPath row] == 0) {
cell.textLabel.text = @"Select All";
cell.textLabel.font = [UIFont boldSystemFontOfSize:13.0f];
}
else {
cell.textLabel.text = @"Some Text Here"
cell.detailTextLabel.text = @"Another piece of text here"
}
return cell;
我做%10
因爲行爲11行後重復,因此試圖爲每11行創建新的對象。
我didSelectRowAtIndexPath
methos代碼
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
if ([indexPath row] != 0) {
NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
tempCell.accessoryType = UITableViewCellAccessoryNone;
}
cell.accessoryType = UITableViewCellAccessoryNone;
}
else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
if ([indexPath row] == 0) {
for (int i = 0; i < [dataSource count]; i++) {
NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:i+1 inSection:0];
UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
tempCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else{
tempCell.accessoryType = UITableViewCellAccessoryNone;
}
}
}
請幫我多選或任何其它的方式來解決多重選擇的問題。
在此先感謝!
發佈您的代碼可能是?最有可能你正在重用cellFor錯誤在cellForRowAtIndexPath方法 – Vladimir 2011-05-19 11:21:29
張貼您的cellforrowindex tableview代碼 – 2011-05-19 11:26:20
檢查http://stackoverflow.com/questions/4616345/select-multiple-rows-in-uitableview/4616432例如 – Vladimir 2011-05-19 12:35:57