- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell"];
if (cell == nil)
{
[tableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"myCell"];
cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell"];
}
if (cell.tag == 0)
{
}
str = [jsonData objectAtIndex:cell.tag];
NSDictionary *dict = [jsonData objectAtIndex:indexPath.row];
cell.lblDeliveryTime.text = [dict valueForKey:@"sysord_ExpectedDeliveryTime"];
cell.lblOrderPlacedTime.text = [dict valueForKey:@"sysord_OrderDateTime"];
cell.lblDeliveryPickUP.text = [dict valueForKey:@"sysord_DeliveryType"];
NSDictionary *dict1 = [jsonData objectAtIndex:cell.tag];
orderidString = [dict1 valueForKey:@"sysord_ID"];
DetailViewController *detailVC=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
return cell;
}
Asked
Active
Viewed 4,088 times
-5

Samir
- 902
- 9
- 23

kinjal shah
- 48
- 1
- 7
-
Which line gives the error? (Hint: step through with the debugger to find out.) – Phillip Mills Jun 23 '15 at 12:03
-
Which line exactly? I guess that's one of the three "cell.ZzZ.text" or `orderidString`. The value from `dict` (or `dict1`) is a `NSNumber` and you use it as it was a `NSString`. – Larme Jun 23 '15 at 12:05
-
You haven't set tag to cell, and trying to access values based on cell.tag. It will not work. Also you are assigning [jsonData objectAtIndex:cell.tag] to str as well as dict1. Its not clear. What is happening here. However [jsonData objectAtIndex:indexPath.row] make sense as indexpath will generate automatically. – Samir Jun 23 '15 at 12:06
-
possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Jun 23 '15 at 12:11
2 Answers
4
One of the values is not a NSString
but NSNumber
.
I would advise you to first check the type but if you want to always convert to string, you can use:
cell.lblDeliveryPickUP.text = [NSString stringWithFormat:@"%@", dict[@"sysord_DeliveryType"]];

Sulthan
- 128,090
- 22
- 218
- 270
-
@Droppy Ideally, you wouldn't even keep the data as JSON. You would parse it beforehand to an object with properties with correct types. – Sulthan Jun 23 '15 at 12:10
2
When you assign an object from dictionary to a text
, you need to make sure it's a NSString type.
cell.lblDeliveryTime.text = [[dict objectForKey:@"sysord_ExpectedDeliveryTime"] stringValue];
cell.lblOrderPlacedTime.text = [[dict objectForKey:@"sysord_OrderDateTime"] stringValue];
cell.lblDeliveryPickUP.text = [[dict objectForKey:@"sysord_DeliveryType"] stringValue];

Grzegorz Krukowski
- 18,081
- 5
- 50
- 71