获取 UITextField [textField frame] 时遇到问题;
当前代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"begin edit: %@", textField);
}
相关输出:
2011-10-30 09:12:08.436 My Project[83470:207] begin edit: <UITextField: 0x6c349d0; frame = (112 2; 182 39); text = 'My Name'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x6c34af0>>
所以我知道文本字段框架在那里,但是当我尝试抓住它时:
代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"begin edit: %@", [textField frame]);
// also tried textField.frame -- same thing
}
错误:
Thread 1: EXC_BAD_ACCES (code=1, address=0x42e00000)
输出:
(lldb)
我一直在这方面旋转我的轮子,我不知道下一步该去哪里。感谢您阅读我的问题。
** 编辑 - 单元格 xib 实例化(文本字段所在的位置) **
注意: 文本字段来自只是一个表格单元格的 xib 文件。
static NSString *CellIdentifier = @"ValidatedTextViewTableCell";
ValidatedTextViewTableCell *cell = (ValidatedTextViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ValidatedTextViewTableCell" owner:self options:nil];
cell = validatedTextViewTableCell;
self.validatedTextViewTableCell = nil;
}
Current Code:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"begin edit: %@", textField);
}
Related output:
2011-10-30 09:12:08.436 My Project[83470:207] begin edit: <UITextField: 0x6c349d0; frame = (112 2; 182 39); text = 'My Name'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x6c34af0>>
So I know the textfield frame is there, but when I try to grab it:
code:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"begin edit: %@", [textField frame]);
// also tried textField.frame -- same thing
}
error:
Thread 1: EXC_BAD_ACCES (code=1, address=0x42e00000)
output:
(lldb)
I've been spinning my wheels on this and I'm not sure where to go next. Thanks for reading my question.
** EDIT - cell xib instantiation (where the textfield lives) **
note: the textfield comes from a xib file that is just a table cell.
static NSString *CellIdentifier = @"ValidatedTextViewTableCell";
ValidatedTextViewTableCell *cell = (ValidatedTextViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ValidatedTextViewTableCell" owner:self options:nil];
cell = validatedTextViewTableCell;
self.validatedTextViewTableCell = nil;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是行不通的:
因为
frame
是 CGRect 类型,而不是对象,因此仅适用于对象的%@
格式说明符在传递时会爆炸。您需要按每个组件记录帧,如下所示:This won't work:
Because
frame
is a CGRect type, not an object, so the%@
format specifier, which is for objects only, blows up when handed it. You'll need to log the frame by each of its components, like this: