我收到以下错误,无法弄清楚它在哪里。请帮我找出问题所在。 TIA
由于未捕获的异常终止应用程序' 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 :(得分:3)
NSArray
不回复length
,而是回复count
最有可能在value
中你期望NSString
,但是有一个数组
设置值时出错。
答案 1 :(得分:1)
你可能期待不同的东西,并且它有其他类型的值。可能你期待NSString并且它提供任何其他类型。 Youc可以使用id数据类型,以便它可以提供帮助。这解决了我。希望你也好。
答案 2 :(得分:0)
此:
[myDict objectForKey:[keys objectAtIndex:i]];
正在返回NSArray
,而不是NSString
。