Iphone 使用NSMutableArray中的数据填充UITableView
我想用我的Iphone 使用NSMutableArray中的数据填充UITableView,iphone,ios,uitableview,nsmutablearray,Iphone,Ios,Uitableview,Nsmutablearray,我想用我的NSMutableArray中的数据填充我的UITableView,但它得到了一个异常 例外情况: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0xa2ba880' My cellForRowAtIndexPa
NSMutableArray
中的数据填充我的UITableView
,但它得到了一个异常
例外情况:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0xa2ba880'
My cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [callDetailArray objectAtIndex:indexPath.row];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
这是阵列:
Array: (
{
callId = 3;
callKeyword = CALL100;
callName = "Call to All";
callNumber = 5908;
}
)
我想做的是,我的
UITaleView
中的单元格将在callId
、callKeyword
、callName
和callNumber
中显示CellDetailArray
字典中的数据,这样您就可以从NSMutableArray
中获得详细信息,如下所示:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSMutableDictionary *d=(NSMutableDictionary*)[callDetailArray objectAtIndex:indexPath.row];
cell.textLabel.text =[d valueForKey:@"callName"];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
如果要在TableCell中显示所有四个值,必须创建具有四个UIlable和Sate值的customeCell,如:-
YourLable1.text=[d valueForKey:@“callId”]代码>
YourLable2.text=[d valueForKey:@“callKeyword”]代码>
YourLable3.text=[d valueForKey:@“callName”]代码>
YourLable4.text=[d valueForKey:@“callNumber”]
在字典中的CellDetailArray
数据中,这样您就可以从NSMutableArray
获取数据,如下所示:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSMutableDictionary *d=(NSMutableDictionary*)[callDetailArray objectAtIndex:indexPath.row];
cell.textLabel.text =[d valueForKey:@"callName"];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
如果要在TableCell中显示所有四个值,必须创建具有四个UIlable和Sate值的customeCell,如:-
YourLable1.text=[d valueForKey:@“callId”]代码>
YourLable2.text=[d valueForKey:@“callKeyword”]代码>
YourLable3.text=[d valueForKey:@“callName”]代码>
YourLable4.text=[d valueForKey:@“callNumber”]代码>您使用下面的代码
cell.textLabel.text = [[callDetailArray objectAtIndex:indexPath.row]objectForKey:@"callName" ];
您正在尝试访问字典而不是字符串。callDetailArray conatins字典数据。字典中只有字符串可用,因此您必须使用下面代码中使用的objectForKey来访问它
cell.textLabel.text = [[callDetailArray objectAtIndex:indexPath.row]objectForKey:@"callName" ];
您正在尝试访问字典而不是字符串。callDetailArray conatins字典数据。在字典中,只有字符串可用,因此您必须使用objectForKey来访问它:cell.textLabel.text=[d valueForKey:@“callName”]代码>,我真的需要手动操作吗?您可以手动设置,如cell.textlab.text=[d valueForKey:@“callName”]代码>将数据保存到NSMutableDictionary pr NSDictionary中。如果您的数组像myarray==(data1、data2、data3),那么您的第一个方法工作正常。您应该调用字典上的objectForKey:
,而不是valueForKey:
。或者使用现代语法:cell.textLabel.text=callDetailArray[indexPath.row][@“callName”]代码>。关于此:cell.textlab.text=[d valueForKey:@“callName”]代码>,我真的需要手动操作吗?您可以手动设置,如cell.textlab.text=[d valueForKey:@“callName”]代码>将数据保存到NSMutableDictionary pr NSDictionary中。如果您的数组像myarray==(data1、data2、data3),那么您的第一个方法工作正常。您应该调用字典上的objectForKey:
,而不是valueForKey:
。或者使用现代语法:cell.textLabel.text=callDetailArray[indexPath.row][@“callName”]代码>。使用此代码时,它就像一个符咒。我想做的是,在不同的单元格中显示callId
,callKeyword
,callName
和callNumber
。您必须创建尽可能多的标签。您可以使用相同的代码,但键和标签应该不同。使用此代码时,它就像一个符咒。我想做的是,在不同的单元格中显示callId
,callKeyword
,callName
和callNumber
。您必须创建尽可能多的标签。您可以使用相同的代码,但键和标签应该是different@NitinGohel ha为你指明了正确的方向。问题是您试图将字典放入一个属性,该属性需要字符串值。@Nitin Gohel ha为您指明了正确的方向。问题是,您试图将字典放入一个需要字符串值的属性中。