2011-10-30 103 views
1

目前代码:无法取得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) 

我一直纺在此我的车轮,我不知道接下来要去哪里。感谢您阅读我的问题。

**编辑 - 厦门国际银行的细胞实例(其中的文本框住)**

注:文本字段来自于厦门国际银行文件,这只是一个表格单元格。

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; 
} 
+1

我觉得因为有在代码中没有错误,你已经张贴你应该张贴你的代码的其余部分。另外,EXC_BAD_ACCESS通常是由于内存管理问题,所以我们需要如何实例化文本字段变量。 –

+0

@XcodeDev我添加了一些关于文本字段来自哪里的更多信息。让我知道你是否需要看别的东西。 – Jacksonkr

回答

3

这将不起作用:

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); 
+0

zing!做得很好。 – Jacksonkr

+1

而不是编写烦人的格式字符串,你可以这样做 - “NSLog(@”begin edit:%@“,NSStringFromCGRect([textField frame]));'。 –