1

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.

1
  • @Nitin Gohel ha pointed you in the right direction. The problem is that you are trying to put a dictionary into a property which is expecting string value. Commented Feb 21, 2013 at 5:37

2 Answers 2

3

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"];

Sign up to request clarification or add additional context in comments.

3 Comments

With regards to this: cell.textLabel.text =[d valueForKey:@"callName"];, do I really need to do it manually?
you set manualy like cell.textLabel.text =[d valueForKey:@"callName"]; becouse your data into NSMutableDictionary pr NSDictionary. if your Array like myarray==(data1,data2,data3) then your First Method working fine.
You should be calling objectForKey:, not valueForKey: on the dictionary. Or use modern syntax: cell.textLabel.text = callDetailArray[indexPath.row][@"callName"];.
2

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

2 Comments

It works like a charm when using this code. What I want to do is that, displays callId, callKeyword, callName and callNumber in different cells.
you have to create labels as much as you want. and you can use the same the code but keys and label should be different

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.