我想处理多个行选择,即不超过3个数据来自服务(URL)的地方。下面是我尝试过的代码的一部分,但不能处理多行选择。你能抽出一些时间来解决它吗? TIA如何处理来自服务的多行数据选择
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
static NSString *MyIdentifier = @"tableCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
}
}
}
NSDictionary *thisRow = [self.professionArr objectAtIndex:row];
if(_WSConstProfessionID !=nil && ![_WSConstProfessionID isEqual:@"0"] && ![_WSConstProfessionID isEqual:@""] && _WSConstProfessionSelectedIndex ==row ){
cell .accessoryType=UITableViewCellAccessoryCheckmark;
} else {
cell .accessoryType=UITableViewCellAccessoryNone;
}
cell.lblTitle.text = [thisRow objectForKey:_WSColumnProfessionName];
NSString *str=[thisRow objectForKey:_WSColumnProfessionID];
NSString *stra=_WSConstProfessionID;
if ([str isEqualToString:stra]) {
cell .accessoryType=UITableViewCellAccessoryCheckmark;
cell.highlighted=YES;
} else {
cell .accessoryType=UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSUInteger row = [indexPath row];
NSDictionary *thisRow=[self.professionArr objectAtIndex:row];
NSLog(@"%@",[thisRow description]);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
if(_WSConstProfessionID!=nil && ![_WSConstProfessionID isEqual:@"0"] && ![_WSConstProfessionID isEqual:@""] &&_WSConstProfessionSelectedIndex!=row){
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_WSConstProfessionSelectedIndex inSection:0]];
if (cell != nil){
cell .accessoryType=UITableViewCellAccessoryNone;
}
}
if(cell.accessoryType == UITableViewCellAccessoryCheckmark){
_WSConstProfessionID=[thisRow objectForKey:_WSColumnProfessionID];
_WSConstProfessionName=[thisRow objectForKey:_WSColumnProfessionName];
_WSConstProfessionSelectedIndex=row ;
} else {
[email protected]"0";
[email protected]"Select";
_WSConstProfessionSelectedIndex=-1 ;
}
[self.navigationController popViewControllerAnimated:YES];
}
可以显示professionArr值?你希望用户可以选择最多3行。 –