- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
当我在自定义单元格中使用 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 aUIScrollView
.To make sure cells are re-used, make sure you are passing the same string to
dequeueReusableCellWithIdentifier:
that you pass toreuseIdentifier:
when usingalloc/init
to make the cell. This string can not be nil.
所以我认为您应该确保您已将 TableCell
的 reuseIdentifer
属性设置为与您传递给 dequeueReusableCellWithIdentifier 的值相同:
关于IOS 7 UITextField resignFirstResponder 坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19117589/
我有一个很简单的CustomIDatePicker写在 中的类 swift 5 ,顶部有一个工具栏,其中包含一个“完成”按钮。问题是,按下此按钮时键盘从未缩回。我尝试了4种不同的方法,请参阅下面的详细
我正在使用 TPKeyboardAvoiding在我的应用程序中显示键盘时隐藏移动文本字段,但是当我尝试结束编辑文本字段时出现异常。它来自 TPKeyboardAvoiding 中的这个方法: - (
我有 uitextfield 在 uitableview 中输入国家/地区值。当点击该字段时,我将显示已加载国家/地区值的表格 View 。 点击任何单元格时,它会返回到相同的表单,并将所选值添加到国
我有一个带有两个文本字段和一个按钮的LoginViewController。我使用了 Storyboard,因此这些不是以编程方式创建的。它们位于彼此之下。 这是 .h 文件 @interface L
我有一个名为“fieldPassword”的文本字段声明为 IBOutlet @property (strong, nonatomic) IBOutlet UITextField *fieldPass
我正在尝试在执行 NSURLResquest 和加载节目之前按下键盘... [self.txtComentario resignFirstResponder]; 应用程序崩溃...我也已经尝试在 lo
我有一个模态呈现的 View ,其中包含 3 个标签。 第三个标签不应该是可编辑的,并且应该在点击它时显示一个 UIDatePicker,如果它显示则隐藏键盘。 所以我这样做了: - (BOOL)te
我是使用 Swift 进行 stackoverflow 和 iOS 应用程序开发的新手。当我想在我的应用程序中关闭键盘时,我连接 viewcontroller.swift 中的 uitextfield
只有当所有 textFields 都已填充时,我才想为一个 textField resignFirstResponder()。但是由于某种原因它不起作用。不管其他人是否被填满,它只检查一个响应者。 这
我有一个 UITextField 和一个 UIButton。如果在文本字段处于事件状态时点击按钮,我想关闭键盘,但我无法这样做。我尝试在点击按钮时调用 [textField resignFirstRe
我有三个文本框。 vacDate vacTime vacType 当我点击 vacDate 或 vacTime 时,我会显示日期选择器 myDatePicker。 此外,当我点击任何地方时,我会调用隐
我不想显示键盘,而是想在选择文本字段时显示弹出 View (我的代码在底部)。如果键盘没有显示,那么一切正常。但是,如果显示键盘然后选择文本字段,则键盘不会被关闭,firstResponders 一定
首先为我糟糕的英语感到抱歉!! 在我的应用程序中有一个 UIViewController 并且 UIView 在 subViewLogin 中被称为 subViewLogin 有 2 个 UIText
在登录页面中,有两个文本输入框(text1和text2)用于输入用户名和密码。单击登录后,它会在这两个文本框上调用两个 resignFirstResponder。我想知道为什么需要调用这个方法? 最佳
我在 UIWindow 上添加了一个自定义 View (NotifyView),带有关闭按钮(将其从 UIWindow 中删除)。当 PUSH 通知进入 didReceiveRemoteNotific
我正在开发一个应用程序,它有一个 tableView,每个单元格的右侧都有一个 textField(有 20 多个单元格)。除了最后一行,我已经为每一行创建了自定义单元格。最后一行只有一个按钮。 现在
我有一种情况,键盘可能打开,然后 NSTimer 在 TextView 上弹出一个 View 。无论如何要全局关闭键盘而不是从 TextView resignFirstResponder 方法?我问的
-(IBAction)settings:(id)sender { [mileagerate resignFirstResponder]; [mainView bringSubviewT
我有一个第三方键盘,目前包含一个 UISearchBar(即启动时的第一响应者)并且用户能够搜索内容(即 gif)以便能够复制、粘贴、发送给 friend 等。 理论上,在栏中输入文本并按下搜索后,用
这个问题在这里已经有了答案: How do I dismiss the iOS keyboard? (16 个答案) hiding keyboard ios [duplicate] (4 个回答) 关
我是一名优秀的程序员,十分优秀!