根据内容更新UITableViewCell的编辑样式 [英] Update editing style of UITableViewCell depending on contents

查看:224
本文介绍了根据内容更新UITableViewCell的编辑样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类似于iPad联系人的基于表的界面,用户可以通过点击底部的空白行将其添加到行列表中。该表始终处于编辑模式,非空行在左侧应该有一个标准的删除编辑图标。用户开始在最后一个空行开始输入时,应在左侧添加一个删除图标(并添加一个新的空白行)。

I am creating a table-based interface similar to iPad Contacts, in which the user can add to a list of rows by tapping a blank row at the bottom. The table is always in editing mode, and non-blank rows should have a standard delete editing icon to the left. As soon as the user starts typing in the last blank row, a delete icon should be added to the left (and a new blank row added).

有没有人知道使UITableView按需更新编辑样式?一切正常,除非删除图标不会出现,直到用户将视图滚动出来,然后返回视图。

Does anyone know how to make the UITableView update the editing style on demand? Everything works, except that the delete icon doesn't appear until the user scrolls the row out of view and then back into view.

这里是我的editingStyleForRowAtIndexPath实现:

Here's my editingStyleForRowAtIndexPath implementation:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (/* text field contains data */)
   {
      return UITableViewCellEditingStyleDelete;
   }
   else
   {
      return UITableViewCellEditingStyleNone;
   }
}


推荐答案

I昨天也打了同样的问题。你基本上必须切换表视图的编辑模式属性。之后,它将刷新您的单元格的editingStyle。

I fought this same problem yesterday. You basically have to toggle the table view's editing mode property. After you do that, it will refresh your cell's editingStyle.

这里是代码为我做的伎俩:

Here's the code that does the trick for me:

self.tableView.editing = NO;
self.tableView.editing = YES;

这让我觉得与联系人应用程序完全相同的效果。至少,它会刷新您的editingStyle。

This gives what appears to me to be the exact same sort of effect as the contacts app. At a minimum, it will refresh your editingStyle.

这篇关于根据内容更新UITableViewCell的编辑样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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