2012-11-27 29 views
0

为什么我无法获得tableViewCell textField的正确框架?来自TableViewCell的UITextField框架

myCustomCell有一个leftDetailTF和一个rightDetailTF文本字段。

无论我点击哪些单元格/文本区域,下面的日志语句都会生成相同的矩形坐标。 LOG:帧= {{470,1},{200,24}}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

myCustomCell *cell = (myCustomCell*)[tableView cellForRowAtIndexPath:indexPath]; 

NSLog(@"Frame = %@",NSStringFromCGRect(cell.rightDetailTF.frame)); 
+0

通话的cellForRowAtIndexPath将rebulid细胞或得到一个缓存单元,所以不要让你want.you可以在一个阵列记录文本框,并把它调用didSelectRowAtIndexPath方法。 – zt9788

+0

尝试rectForRowAtIndexPath: – combinatorial

+0

我需要rect为rightDetailsTF。 rectForRowAtIndexPath返回单元格的rect而不是单元格中的textField。 – vcirilli

回答

0

如果你想在超视图的超视图中检查子视图的框架,你可以使用它。

CGRect rect = [cell.rightDetailTF.superview convertRect:cell.rightDetailTF.frame toView:self.view]; 
NSLog(@"Rect:%@",NSStringFromCGRect(rect)); 
+0

这张票 - 非常感谢您的帮助。 – vcirilli

+0

哦。不用谢。 – SARANGA

0

首先获得小区的帧...

CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath]; 

然后得到正确的文本字段的帧

CGRect resultFrame = CGRectMake(cellFrame.origin.x + rightDetailTFFrame.origin.x, cellFrame.origin.y + rightDetailTFFrame.origin.y, rightDetailTFFrame.size.width, rightDetailTFFrame.size.height); 
+0

resultFrame origin.x仍然不正确。它看起来像cell.rightDetailTF.origin.x返回了偏移通过像600 – vcirilli

+0

你在你的细胞中layoutSubviews做自定义布局留下了点? – combinatorial

0

使用数组到:...

myCustomCell *cell = (myCustomCell*)[tableView cellForRowAtIndexPath:indexPath]; 
CGRect rightDetailTFFrame = cell.rightDetailTF.frame; 

两个再结合记录rect。

-(UITableViewCell*)cell.......:IndexPath... 
{ 
     CGRect rect = cell.rightDetailTF.cellFrame; 
     NSMutableDictionary* dic = [NSMutableDictionary alloc] init...:4]; 
     [dic setObject:[NSNumber numberWithFloat:rect.origin.x] forKey:...1]; 
     //... rect.origin.y,rect.size.with,rect.size.height 
     [arr addObject:dic]; 
     [dic release]; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
     NSMutableDictionary* dic = [arr objectAtIndex:indexPath.row]; 
     CGRect rect = CGRectMake([dic objectForKey:...1],........); 
} 
0

那么,事情是,在iOS的一个UITableView你的框架是固定的小区中的所有意见。因此,你CAN NOT修改这些框架。无论您为单元格设置了哪个框架,它都会在自动调用[cell reloadData]时恢复。

您是否正确初始化了init方法中的视图?

刚过,乘坐“loadsubviews”的方法在你的“myCustomCell”类。

打印出的CGRect在这种方法中,子视图,如果帧中,正确的,你必须在你初始化在init方法的看法有问题。