0

我正在开发一个图像编辑 iPhone 应用程序。我正在使用UITableView. 我的问题是,当我在表格视图中插入新行时,第三个单元格之后的新表格视图单元格会重复第一个单元格的数据。

我必须进行大量搜索,不幸的是找不到解决方案。谁能查看我的代码并告诉我哪里出错了?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    VerticalFrameCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[VerticalFrameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.imgView.image   = nil;
        cell.tf_Comment.text = nil;
    }

    //add gesture on picture
    UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandlert:)];
    imageTap.delegate    = self;
    [cell.imgView addGestureRecognizer:imageTap];
    //add pinch gesture for zooming image
    UIPinchGestureRecognizer* pinchRecognizer =
    [[UIPinchGestureRecognizer alloc] initWithTarget:self
                                              action:@selector(handlePinch:)];
    pinchRecognizer.delegate        = self;
    [cell.imgView addGestureRecognizer:pinchRecognizer];


    //add pan gesture for plcing text
    UIPanGestureRecognizer *moveText = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveTextOnImge:)];
    moveText.delegate       = self;
    [moveText setMinimumNumberOfTouches:1];
    [moveText setMaximumNumberOfTouches:1];
    [cell.tf_Comment addGestureRecognizer:moveText];




    cell.imgView.tag            = indexPath.row+6000;
    cell.sclView.tag            = indexPath.row+7000;
    cell.btnAddText.tag         = indexPath.row+8000;
    cell.tf_Comment.tag         = indexPath.row+9000;

    return cell;
}

// 在此处添加新的单元格代码

- (IBAction)btnAddNewCell_Action:(id)sender {
    if (objectsArray.count<6) {// not add more then six cell 
        [objectsArray addObject:@"Other's"];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:objectsArray.count-1 inSection:0];
        [tbl_Frame insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
        [tbl_Frame  scrollToRowAtIndexPath:indexPath  atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }else{
        [AppUtility displayAlertWithTitle:AlertTitle AndMessage:@"You can't take more then six images"];
    }
}
4

0 回答 0