我试图使用几个不同的重用标识符,让用户能够输入数据没有segue ...(只是觉得它会很好)。为什么没有(cell == nil)工作?
这是我第一次尝试:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(addC && indexPath.row == 0 && indexPath.section == 0){
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
UITextField *txtField = [[UITexField alloc] initWithFrame:CGRectMake(10, 7, 260, 30);
[cell addsubview:txtField];
cell.txtField.delegate = self;
cell.txtField.text = nil;
return cell;
不过,我注意到,如果我使用的字段不止一次文本字段会重复,留下旧值下方。 因此,一些reasearch后,我说:
if(cell == nil){
}
围绕txtField初始化,但它不会开火。我结束了解决此问题的工作完全由制作一个单独的UITableViewCell类,但现在我想补充 SWTableViewCell 和改变从我的UITableViewCell小区到CustomTableViewCell。附加到我的表和初始化
这种定制的实用程序需要使用
if (cell == nil) {
NSMutableArray *leftUtilityButtons = [NSMutableArray new];
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
icon:[UIImage imageNamed:@"check.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0]
icon:[UIImage imageNamed:@"clock.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0]
icon:[UIImage imageNamed:@"cross.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0]
icon:[UIImage imageNamed:@"list.png"]];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0]
title:@"More"];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:@"Delete"];
cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier
containingTableView:_tableView // For row height and selection
leftUtilityButtons:leftUtilityButtons
rightUtilityButtons:rightUtilityButtons];
cell.delegate = self;
}
如果还没有实现这个插件,但是当我研究我的问题,现在我还没有发现任何东西之前。
我也曾尝试
if (cell.contentView == nil)
if (cell.contentView.subViews == nil)
if (cell.subViews == nil)
,但由于某种原因,将不会触发第一次像它应该。我究竟做错了什么?
如果我可以投票你,我会多数民众赞成正是我是如何解决我的第一个问题,但接着下一个,如果你看看他使用的SWTableViewCell if(cell == nil)复制那个。因为它不会被称为ID必须翻拍他的整个项目几乎使用它? theres暂时没有解决方法 – Snymax
只需将代码放入'initWithStyle:reuseIdentifier:'我将编辑我的答案并举例说明如何工作。 – Dima
试图模拟这个后,它看起来像默认的'SWTableViewCell'初始值设定程序期望引用'UITableView',这是不容易从该点访问。因此,我会建议摆脱注册的单元格,而是结构化代码以允许手动初始化单元格,就像他们的文档中的代码示例一样。 – Dima