Xcode 索引路径行的表视图方法单元格再次重新加载,然后应用程序崩溃

Xcode 索引路径行的表视图方法单元格再次重新加载,然后应用程序崩溃,xcode,ipad,uitableview,Xcode,Ipad,Uitableview,在我的应用程序中,一行有一个表视图和4个图像视图。当我滚动表格视图时,会再次调用索引路径处行的单元格方法,然后应用程序崩溃。如何防止滚动时重新加载表视图。我的代码是:- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; static NSString *AutoCo

在我的应用程序中,一行有一个表视图和4个图像视图。当我滚动表格视图时,会再次调用索引路径处行的单元格方法,然后应用程序崩溃。如何防止滚动时重新加载表视图。我的代码是:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";


    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];

        for (int i=0; i <= [wordsInSentence count]; ++i) {
            UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(30+90*(i%4), 15, 80, 100)] autorelease] ;
            imageView1.tag = i+1;

            [imageViewArray insertObject:imageView1 atIndex:i];
            [cell.contentView addSubview:imageView1];
        }

    }

    int photosInRow;

    if ( (indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1) || ([wordsInSentence count] % 4 == 0) ) {
        photosInRow = 4;
    } else {
        photosInRow = [wordsInSentence count] % 4;
    }

    for ( int i = 1; i <=photosInRow ; i++ ){
        imageView = (UIImageView *)[cell.contentView viewWithTag:j];
        [self showImage:imageView];
    }

    return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=nil;
静态NSString*AutoCompleteRowIdentifier=@“AutoCompleteRowIdentifier”;
单元格=[tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:AutoCompleteRowIdentifier]自动释放];

对于(int i=0;i我看到的唯一问题是

for ( int i = 1; i <= photosInRow ; i++ ){
    imageView = (UIImageView *)[cell.contentView viewWithTag:j];
    [self showImage:imageView];
}
因此,我看到的另一个缺陷是这里的逻辑

for (int i=0; i <= [wordsInSentence count]; ++i) {
    UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(30+90*(i%4), 15, 80, 100)] autorelease] ;
    imageView1.tag = i+1;

    [imageViewArray insertObject:imageView1 atIndex:i];
    [cell.contentView addSubview:imageView1];
}

for(int i=0;i@Christian)请花些时间格式化您的问题。这很有帮助。sry将在以后继续讨论,请给我答案
for (int i=0; i <= [wordsInSentence count]; ++i) {
    UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(30+90*(i%4), 15, 80, 100)] autorelease] ;
    imageView1.tag = i+1;

    [imageViewArray insertObject:imageView1 atIndex:i];
    [cell.contentView addSubview:imageView1];
}
for (int i = 0; i < 4; ++i) {
    UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(30+90*(i%4), 15, 80, 100)] autorelease] ;
    imageView1.tag = i+1;

    int trueImageIndex = indexPath.row * 4 + i;
    [imageViewArray insertObject:imageView1 atIndex:trueImageIndex];

    [cell.contentView addSubview:imageView1];
}