gpt4 book ai didi

IOS 7 UITextField resignFirstResponder 坏

转载 作者:技术小花猫 更新时间:2023-10-29 11:20:13 32 4
gpt4 key购买 nike

当我在自定义单元格中使用 UItextField 时,以及当我 resignFirstResponder 文本字段时,我遇到了崩溃,但它不再可见(表格 View 滚出窗口)。我仍然可以找到文本字段,指针继续可访问,它不是空的,并且崩溃只发生在 IOS7 上,在 IOS6 上我没有这个问题。这是一些代码:

textField 是一个全局变量。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];

TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[TableCell alloc] init];

if(indexPath.row == 0)
{
[textField setFrame:CGRectMake(15, 5, cell.frame.size.width-60, cell.frame.size.height)];
textField.textAlignment = NSTextAlignmentLeft;
[textField setBorderStyle:UITextBorderStyleNone];
textField.textColor = [UIColor blackColor];
textField.tag = indexPath.row;
textField.delegate = self;
textField.secureTextEntry = YES;
[textField setFont:[UIFont fontWithName:@"Arial-BoldMT" size:15]];
textField.textColor = [UIColor whiteColor];
textField.returnKeyType = UIReturnKeyDone;
[textField setAdjustsFontSizeToFitWidth:YES];
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Senha" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[cell.contentView textField];
}
}
return cell;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
// NSLog(@"text field %@",textField);
// NSLog(@"tfield return: %d",textField.isFirstResponder);
[textField resignFirstResponder];
// [self.view endEditing:YES];

return NO;
}

最佳答案

在 Apple 的帮助下,我已经成功修复了一个类似的崩溃错误。关键是 reuseIdentifer

引述来自 Apple 开发人员技术支持Vincent Gable 的邮件:

This is a known behavior change that happens in iOS 7 with UITableView, when cells are not reused.

The fix here is to make sure that you follow proper cell reuse. If you do not want to re-use UITableViewCells, then it is recommended that you simply layout all your views inside a UIScrollView.

To make sure cells are re-used, make sure you are passing the same string to dequeueReusableCellWithIdentifier: that you pass to reuseIdentifier: when using alloc/init to make the cell. This string can not be nil.

所以我认为您应该确保您已将 TableCellreuseIdentifer 属性设置为与您传递给 dequeueReusableCellWithIdentifier 的值相同:

关于IOS 7 UITextField resignFirstResponder 坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19117589/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com