Reputation: 668
I want to populate my UITableView
with data from my NSMutableArray
but it is getting an exception.
The exception:
*** 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;
}
This is the array:
Array: (
{
callId = 3;
callKeyword = CALL100;
callName = "Call to All";
callNumber = 5908;
}
)
What I want to happen is that the cells in my UITaleView
will display the data in callId
, callKeyword
, callName
and callNumber
.
Upvotes: 1
Views: 3914
Reputation: 2002
you use below code
cell.textLabel.text = [[callDetailArray objectAtIndex:indexPath.row]objectForKey:@"callName" ];
You are trying access dictionary instead of string. callDetailArray conatins dictionary data. inside the dictionary only strings are available so you must need to access it by using objectForKey
Upvotes: 2
Reputation: 49720
In you CellDetailArray
Data In Dictionary
so you can Get Deta From NSMutableArray
like Bellow:-
- (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;
}
if you want to show all four value in to your TableCell have to Create customeCell with Four UIlable and Sate Value like:-
YourLable1.text =[d valueForKey:@"callId"];
YourLable2.text =[d valueForKey:@"callKeyword"];
YourLable3.text =[d valueForKey:@"callName"];
YourLable4.text =[d valueForKey:@"callNumber"];
Upvotes: 3