1

我有一个带导航栏的 tableview 控制器,它用于用户配置文件屏幕。tableview 有 10 个包含标签、文本字段和 textview 的自定义单元格,导航栏按钮用于启用/禁用 tableviewcell 内容的编辑。用户可以使用该视图控制器上的按钮从应用程序中的任何控制器加载此用户配置文件屏幕。我想要做的是,当用户选择从任何地方打开此用户配置文件屏幕(tableview 控制器)时,它应该只显示查看模式;其具有文本字段和 Textviews 的单元格不应该是可编辑的。但是,当用户浏览应用程序的设置屏幕并转到用户个人资料屏幕时,可能会启用或禁用其单元格以进行编辑。有什么建议吗?

4

1 回答 1

0

尝试这个:

第 1 部分。准备UITableViewController课程

  1. .h中:
    • @property (nonatomic, assign) BOOL enableCellSelection;
      ...
  2. .m

    • -initWithStyle:做...

      - (id)initWithStyle:(UITableViewStyle)style
      {
          self = [super initWithStyle:style];
          if (self) {
              enableCellSelection = YES;
          }
          return self;
      }
      
    • -cellForRowAtIndexPath:做...

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
      //your normal cell handling code
      
      [cell setUserInteractionEnabled:(enableCellSelection ? UITableViewCellSelectionStyleBlue : UITableViewCellSelectionStyleNone)];
      return cell;
      }
      

第 2 部分。展示你的UITableViewController班级

从任何方法...

//alloc/init normally
MyTableViewController *tvcObj = [[MyTableViewController alloc] init];

//explicitly disable the cell selection ability 
tvcObj.enableCellSelection = NO;

//display the tableView
[self.navigationController pushViewController:tvcObj animated:YES];

基本上,我们创建一个在显示之前设置的属性,tableView当表格加载时,它将读取该属性并适当地设置整个单元格的交互能力。
这是我能想到的最好的

于 2013-12-02T09:51:53.857 回答