1
votes

am getting the following error, cannot figure it out where it is. Please help me to find out the issue. TIA

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x145ecca0' *** First throw call stack:

- (void)viewDidLoad
    {
        [super viewDidLoad];
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont fontWithName:@"Helvetica neue" size:20.0];
        //label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        //label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor whiteColor]; // change this color
        self.navigationItem.titleView = label;
        label.text = @"My Details";
        [label sizeToFit];
    }

    #pragma mark -
    #pragma mark Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.

        return 30;
    }


    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
            cell.textLabel.font=[UIFont fontWithName:@"Helvetica neue" size:14.0];
            cell.detailTextLabel.font=[UIFont fontWithName:@"Helvetica neue" size:13.0];
            cell.textLabel.textColor=[UIColor colorWithRed:199.0/255.0 green:65.0/255.0 blue:69.0/255.0 alpha:1.0];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }

        NSArray *keys = [myDict allKeys];

        for(int i=0 ; i<[keys count]; i++ )
        {

            NSString *value=[myDict objectForKey:[keys objectAtIndex:i]];
            if ([value isEqual: [NSNull null]]||[value length]==0) {

                [myDict setValue:@"--" forKey:[keys objectAtIndex:i]];

            }

        }

        if(indexPath.row==0)
        {
            cell.textLabel.text = @"Relationship";
            cell.detailTextLabel.text=[myDict objectForKey:@"Relationship"];
        }

        if(indexPath.row==1)
        {
            cell.textLabel.text = @"Person Name";
            cell.detailTextLabel.text=[myDict objectForKey:@"PersonName"];
        }

        if(indexPath.row==2)
        {
            cell.textLabel.text = @"Shopping";
            cell.detailTextLabel.text=[myDict objectForKey:@"shopping"];
        }
        if(indexPath.row==3)
        {
            cell.textLabel.text = @"Quantity";
            cell.detailTextLabel.text=[myDict objectForKey:@"Quantity"];
        }
        if(indexPath.row==4)
        {
            cell.textLabel.text = @"Pants";
            cell.detailTextLabel.text=[myDict objectForKey:@"pants"];
        }
        if(indexPath.row==5)
        {
            cell.textLabel.text = @"Shirts";
            cell.detailTextLabel.text=[myDict objectForKey:@"shirts"];
        }
        if(indexPath.row==6)
        {

            cell.textLabel.text = @"Other";
            cell.detailTextLabel.text=[myDict objectForKey:@"other"];
        }
        if(indexPath.row==7)
        {
            cell.textLabel.text = @"Start Date";
            NSString *str=[myDict objectForKey:@"startDate"];
            NSString *str2= [str substringToIndex:10];
            cell.detailTextLabel.text=str2;
        }
        if(indexPath.row==8)
        {
            cell.textLabel.text = @"End Date";
            NSString *str=[myDict objectForKey:@"endDate"];
            NSString *str2= [str substringToIndex:10];
            cell.detailTextLabel.text=str2;
        }
        if(indexPath.row==9)
        {
           cell.textLabel.text = @"Address";
           cell.detailTextLabel.text=[myDict objectForKey:@"address"];
        }
        if(indexPath.row==10)
        {
            cell.textLabel.text = @"Notes";
            cell.detailTextLabel.text=[myDict objectForKey:@"Notes"];
        }
        if(indexPath.row==11)
        {
            cell.textLabel.text = @"Bill";
            cell.detailTextLabel.text=[myDict objectForKey:@"bill"];
        }
        if(indexPath.row==12)
        {
            cell.textLabel.text = @"Grand Total";


            cell.detailTextLabel.text=[myDict objectForKey:@"total"];

        }
        if(indexPath.row==13)
        {
            cell.textLabel.text = @"Signature";
            cell.detailTextLabel.text=[myDict objectForKey:@"sign"];
        }

        return cell;
    }
3
Aside from the issue consider to use an array as data source and / or static cells at all. - vadian

3 Answers

4
votes

NSArray do not respond to length, but count.
Most probably in value you expect a NSString, but there is an array instead.
Something is wrong when you set the value.

2
votes

Might be you are expecting something different and it having other type of values.May be you are expecting NSString and it is giving any other type. Youc can use id data type so that it can be helpful. This solved for me.Hope for you also.

1
votes

This:

[myDict objectForKey:[keys objectAtIndex:i]];

is returning an NSArray, not a NSString.