2017-01-26 41 views
-1

我得到以下错误,无法弄清楚它在哪里。请帮我找出问题。 TIA- [__ NSArrayM长度]:无法识别的选择器发送到实例0x145ecca0

终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [__ NSArrayM长]:无法识别的选择发送到实例0x145ecca0' ***第一掷调用堆栈:

- (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; 
    } 
+0

除了这个问题,考虑使用数组作为数据源和/或静态单元。 – vadian

回答

2

NSArray不回应length,但count
最有可能在value您期望NSString,但有一个数组。
设置该值时发生错误。

0

此:

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

是返回一个NSArray,而不是NSString

1

可能是你期待着不同的东西,它有其他类型的值。可能是你期待NSString,它是给任何其他类型。 Youc可以使用id数据类型,以便它可以有所帮助。这解决了我的问题,希望你也。

相关问题