我已經編寫了用於顯示帶有3個部分的tableview的代碼,現在我想將選定的行項存儲到一個數組中,並且當我嘗試了下面的代碼時,數組值爲零。建議我該如何解決這個問題 下面我加入的代碼和JSON樣本數據如何在tableview中將多個選定的行項存儲在可變數組中
{
"technicians": {
"group": [
{
"first_name": "First",
"last_name": "Available",
"id": ""
},
{
"first_name": "idea",
"last_name": "Chandra",
"id": 2885
},
{
"first_name": "manson",
"last_name": "Tolios",
"id": 2878
},
{
"first_name": "tata",
"last_name": "Masson",
"id": 2869
}
],
"client": [
{
"first_name": "tsms",
"last_name": "ysys",
"id": 2875
},
{
"first_name": "Oscar",
"last_name": "tata",
"id": 2851
},
{
"first_name": "Peter",
"last_name": "yaha",
"id": 2873
},
{
"first_name": "iaka",
"last_name": "adad",
"id": 2847
},
{
"first_name": "taga",
"last_name": "uaja",
"id": 2917
}
],
"contractors": [
{
"first_name": "taha"
},
{
"first_name": "haka"
},
{
"first_name": "oala"
}
]
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"EcsStafflist"];
if(!cell)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
}
UILabel *Fname = (UILabel *)[cell viewWithTag:18];
UILabel *Lname = (UILabel *)[cell viewWithTag:19];
Fname.text = [[[mydic objectForKey:[MysectionTitles objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row]valueForKey:@"first_name"];
Lname.text = [[[mydic objectForKey:[MysectionTitles objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row]valueForKey:@"last_name"];
if (indexPath.row %2 ==1)
cell.backgroundColor = [UIColor colorWithRed:0.60 green:0.60 blue:0.95 alpha:1.0];
else
cell.backgroundColor = [UIColor colorWithRed:0.64 green:0.89 blue:0.61 alpha:1.0];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
stringId = [[[mydic objectForKey:[MysectionTitles objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row]objectForKey:@"id"];
if
([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}else{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
[myArray addObject:stringId];
NSLog(@"myArray %@",myArray);
}
}
具有u初始化myArray的? –
是的,我已經初始化@hamentmiglani –
你在哪裏得到零?如果您在初始化數組時遇到問題,那麼這與tableview函數無關。你確認你的數組是否正確填充? – Russell