当前代码:

- (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;
}

最佳答案

这行不通:

NSLog(@"begin edit: %@", [textField frame]);

因为frame是CGRect类型,而不是对象,所以仅用于对象的%@格式说明符在传递时会炸毁。您需要按框架的每个组件记录框架,如下所示:
NSLog(@"begin edit: %f, %f, %fx%f", [textField frame].origin.x [textField frame].origin.y, [textField frame].size.width, [textField frame].size.height);

10-07 19:50
查看更多