iOS Parse' NSRangeException',原因:' *** - [__ NSArrayI objectAtIndex:]:索引1超出边界[0 .. 0]

时间:2015-01-19 17:55:18

标签: ios parse-platform

我试图将解析数据添加到我的表数组中并且我得到'NSRangeException',原因:'*** - [__ NSArrayI objectAtIndex:]:索引1超出边界[0 .. 0]任何有关如何解决此问题的帮助将不胜感激。

PFQuery *query31 = [PFQuery queryWithClassName:@"Salesman"];
        [query31 whereKey:@"SalesNo" equalTo:self.tbl22];
      //   query31.cachePolicy = kPFCachePolicyCacheThenNetwork;
        [query31 getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
            if (!object) {
                NSLog(@"The getFirstObject request failed.");
            } else {
                self.salesman = [object objectForKey:@"Salesman"];
                NSLog(@"salesStr is %@",self.salesman);
            }
        }];

 tableData2 = [NSArray arrayWithObjects:t21, t22, t23, t24, t25, nil];

这是我得到崩溃t22 =自我推销员

if ([_formController isEqual: @"Leads"]) {

    if ( ( ![t22 isEqual:[NSNull null]] ) && ( [self.tbl22 length] != 0 ) )
            {t22 = self.salesman;
    } else { t22 = @"None"; }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([tableView isEqual:self.listTableView]) {
        return [tableData count];
    } else if ([tableView isEqual:self.listTableView2]) {
        return [tableData count];
    } else if ([tableView isEqual:self.newsTableView]) {
        return 1;
    }
      return 0;
}

#pragma mark TableView Delegate Methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([tableView isEqual:self.listTableView]) {

    static NSString *CellIdentifier = @"NewCell";
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (myCell == nil) {
        myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }
        //need to reload table (void)viewDidAppear to get fonts to change but its annoying
    myCell.textLabel.text = [tableData4 objectAtIndex:indexPath.row];
    myCell.textLabel.font = [UIFont systemFontOfSize:8.0];
   [myCell.textLabel setTextColor:[UIColor darkGrayColor]];
    myCell.detailTextLabel.text = [tableData objectAtIndex:indexPath.row];
    myCell.detailTextLabel.font = [UIFont boldSystemFontOfSize:8.0];
   [myCell.detailTextLabel setTextColor:[UIColor blackColor]];

    return myCell;
}
    else if ([tableView isEqual:self.listTableView2]) {

    static NSString *CellIdentifier2 = @"NewCell2";
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

    if (myCell == nil) {
        myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2]; }
        //need to reload table (void)viewDidAppear to get fonts to change but its annoying
    myCell.textLabel.text = [tableData3 objectAtIndex:indexPath.row];
    myCell.textLabel.font = [UIFont systemFontOfSize:8.0];
   [myCell.textLabel setTextColor:[UIColor darkGrayColor]];
    myCell.detailTextLabel.text = [tableData2 objectAtIndex:indexPath.row];
    myCell.detailTextLabel.font = [UIFont boldSystemFontOfSize:8.0];
   [myCell.detailTextLabel setTextColor:[UIColor blackColor]];

        //draw red vertical line
    UIView *vertLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, myCell.frame.size.height)];
    vertLine.backgroundColor = [UIColor redColor];
    [myCell.contentView addSubview:vertLine];

    return myCell;
}
    else if ([tableView isEqual:self.newsTableView]) {

    static NSString *CellIdentifier1 = @"detailCell";
    CustomTableViewCell *myCell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1 forIndexPath:indexPath];

    if (myCell == nil) {
        myCell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1]; }
     //need to reload table (void)viewDidAppear to get fonts to change but its annoying
    myCell.separatorInset = UIEdgeInsetsMake(0.0f, myCell.frame.size.width, 0.0f, 400.0f);
    myCell.leadtitleLabel.text = self.lnewsTitle;
    myCell.leadtitleLabel.numberOfLines = 0;
    myCell.leadtitleLabel.font = [UIFont systemFontOfSize:12.0];
   [myCell.leadtitleLabel setTextColor:[UIColor darkGrayColor]];
    myCell.leadsubtitleLabel.text = @"Yahoo Finance 2 hrs ago";
    myCell.leadsubtitleLabel.font = [UIFont systemFontOfSize:8.0];
   [myCell.leadsubtitleLabel setTextColor:[UIColor grayColor]];
    myCell.leadreadmore.text = @"Read more";
    myCell.leadreadmore.font = [UIFont systemFontOfSize:8.0];
    myCell.leadnews.text = comments;
    myCell.leadnews.numberOfLines = 0;
    myCell.leadnews.font = [UIFont boldSystemFontOfSize:8.0];
   [myCell.leadnews setTextColor:[UIColor darkGrayColor]];

return myCell;
}

当我运行log时,我得到一个结果Salesman名称

NSLog(@"salesStr is %@",self.salesman);
salesStr is Adam Monteleone

1 个答案:

答案 0 :(得分:0)

这意味着您的数组为空,并且您尝试访问无法获取它的索引1。你最好调试自己。

如果你想对NSString进行内省,你只需要使用length方法进行检查。如果您的NSString为nil或为空,它将返回false

相关问题