我在一个单元格上有两个视图,当我单击一个单元格时,它将被隐藏,一个编辑表单将在其上展开.如何解决? [英] I have two views on one cell, when I click on a cell it will be hidden and one edit form will be expanded on that. How to resolve that?

查看:21
本文介绍了我在一个单元格上有两个视图,当我单击一个单元格时,它将被隐藏,一个编辑表单将在其上展开.如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 初学者.我有一个带有两个自定义视图的 tableview 单元格:一个是项目单元格,一个是编辑该单元格.当用户点击项目时,该项目将被隐藏,该单元格的编辑表单将在其上展开.

I'm a beginner iOS. I have one cell of tableview with two custom views: one is item cell and one is edit form that cell. When user click on item, that item will be hidden and the edit form of that cell will be expanded on that.

我该如何解决这个问题.谢谢!

How I can resolve that problem. Thank you!

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MinimumCell *cell1 = (MinimumCell *)[tableView dequeueReusableCellWithIdentifier:@"MinimumCell"];
    if (cell1 == nil) {
        cell1 = (MinimumCell *)[MinimumCell cellFromNibNamed:@"MinimumCell"];

    }
    ExtendCell *cell2 = (ExtendCell *)[tableView dequeueReusableCellWithIdentifier:@"ExtendCell"];
    if (cell2 == nil) {
        cell2 = (ExtendCell *)[ExtendCell cellFromNibNamed:@"ExtendCell"];

    }
    if(isEditClicked && selectedIndexPath.section == indexPath.section && selectedIndexPath.row == indexPath.row ){
        return cell2;
    }
    return cell1;
}

默认会显示cell1,当用户点击那个cell时,cell1会被cell2替换(编辑表单).它以展开动画出现.

The default it will show cell1, when user click on that cell, cell1 is replace with cell2 (edit form). It is appear with expand animation.

推荐答案

在单击行时使用 didSelectRowAtIndexPath 重新加载该单元格[tableView reloadRowsAtIndexPaths: withRowAnimation: ];

Use didSelectRowAtIndexPath on click of row to reload that cell using [tableView reloadRowsAtIndexPaths: withRowAnimation: ];

通过以下方法使用您的 cellForRowAtIndex..

Use your cellForRowAtIndex with following methods..

如下图所示,您可以使用此方法在两个 Cell 视图之间切换.

As shown below ,you can toggle between two Cell view using this method.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

// isEditCell is bool variable used to toggle between cell types.

isEditCell=[self shouldToggleView:[tableView cellForRowAtIndexPath:indexPath] ];

NSArray *ll=[[NSArray alloc]initWithObjects:indexPath, nil];
[tableView reloadRowsAtIndexPaths:ll withRowAnimation:UITableViewRowAnimationAutomatic];

}


-(BOOL )shouldToggleView:(UIView *)view {

while (view != nil) {
    if ([view isKindOfClass:[TableViewEditCell class]]) {
        return  NO; //[tbl indexPathForCell:(TableViewEditCell *)view];
    }else  if ([view isKindOfClass:[TableViewCell class]]) {
        return   YES;//[tbl indexPathForCell:(TableViewCell *)view];
    }
    else {
        view = [view superview];
    }
}

return nil;

}

这篇关于我在一个单元格上有两个视图,当我单击一个单元格时,它将被隐藏,一个编辑表单将在其上展开.如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆