iPhone:超越界限[0 .. 8]'

jdo*_*dog 0 iphone nsarray ios

这真让我抓狂!我一直在崩溃这个错误.以下是我的代码.我试图在我的UITabelView中添加一个额外的单元格以获得"25个以上"的功能.但是我在heightForRowAtIndexPath函数内部崩溃了.我在俯瞰什么?

TIA.

[NSMutableArray objectAtIndex:]:索引4294967295超出边界[0 .. 8]'

0 CoreFoundation
0x01338be9 __exceptionPreprocess + 185 1 libobjc.A.dylib
0x0148d5c2 objc_exception_throw + 47 2 CoreFoundation
0x0132e6e5 - [__ NSArrayM objectAtIndex:] + 261 3
mackdabMobile
0x00004f56 - [AllmackTableViewController tableView:heightForRowAtIndexPath:] +

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
    {
        NSLog(@"IndexRow int: %i", indexPath.row);
        NSLog(@"postsArray count: %i", [postsArray count]);
        if(indexPath.row < [postsArray count]){  **<----Where it crashes**
            Post *myPost = [postsArray objectAtIndex:[indexPath row] - 1];
            NSString *text = myPost.description;

            CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 88.0f);

            CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

            CGFloat height = MAX(size.height, 35.0f);

            return height + (CELL_CONTENT_MARGIN * 2) + 28.0f;
        }else{
            return 100.0f;
        }


    }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


        // Return 1 section which will be used to display the giant blank UITableViewCell as defined
        // in the tableView:cellForRowAtIndexPath: method below
        if ([self.postsArray count] == 0){

            return 1;

        } else if ([self.postsArray count] < 25) { //self.webServiceDataModel.total

            // Add an object to the end of the array for the "Load more..." table cell.
            NSLog(@"postsArray count: %i", [postsArray count]);
            return [self.postsArray count] + 1;
            NSLog(@"postsArray count after +1: %i", [postsArray count]);

        }   
        // Return the number of rows as there are in the postsArray Post data is empty.
        return [self.postsArray count];

    }
Run Code Online (Sandbox Code Playgroud)

Kin*_*iss 5

[indexPath row] - 1 是问题,

对于indexpath.row = 0,它将为-1.

[array objectAtIndex:-1]是个例外.所以崩溃发生了.