I am having a crush problem. This is the first thing that I couldn't find the solution online. Please help if you had same problem before. Thanks.
Error message:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x3a072a70'
Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *lblCategoryName;
UILabel *lblGroupName;
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
lblCategoryName = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 280, 20)];
[lblCategoryName setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]];
[lblCategoryName setTag:1];
[cell.contentView addSubview:lblCategoryName];
lblGroupName = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 280, 20)];
[lblGroupName setFont:[UIFont fontWithName:@"HelveticaNeue-Italic" size:10]];
[lblGroupName setTag:2];
[cell.contentView addSubview:lblGroupName];
}
POCategory *category = [self.variantCategories objectAtIndex:indexPath.row];
lblCategoryName = (UILabel*)[cell.contentView viewWithTag:1];
[lblCategoryName setText:category.CategoryName];
lblGroupName = (UILabel*)[cell.contentView viewWithTag:2];
[lblGroupName setText:category.GroupName];
return cell;
}
The weird thing is; It is working perfectly when I comment out the following lines OR when my array "variant.Categories" is empty. (I can even fill the tableview from another functions) However it is not crushing in these lines. And I can see the object while debugging. It is not empty. Everything looks normal.
//POCategory *category = [self.variantCategories objectAtIndex:indexPath.row];
//lblCategoryName = (UILabel*)[cell.contentView viewWithTag:1];
//[lblCategoryName setText:category.CategoryName];
//lblGroupName = (UILabel*)[cell.contentView viewWithTag:2];
//[lblGroupName setText:category.GroupName];
"variantCategories" array is defined like this in my UITableViewController class, and this is the only variable that I am passing to this view controller.
@property (nonatomic, retain) NSArray *variantCategories;
I tried to make it "strong" instead of "retain" but it didn't work.
Any kind of help highly appreciated.
Thanks.