2012-11-27 2 views
0

tableViewCell textField에 대한 올바른 프레임을 가져올 수없는 이유는 무엇입니까?TableViewCell의 UITextField 프레임

myCustomCell에는 leftDetailTF 및 rightDetailTF 텍스트 필드가 있습니다.

아래의 로그 문은 내가 탭하는 셀/텍스트 필드와 상관없이 동일한 rect 좌표를 생성합니다. 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

call cellForRowAtIndexPath는 셀을 리빌드하거나 캐시 된 셀을 가져 오므로 원하는 것을 얻지 못합니다. 텍스트 필드를 배열에 기록하고 didselectRowAtIndexPath에서이를 호출 할 수 있습니다. – zt9788

+0

try rectForRowAtIndexPath : – combinatorial

+0

rightDetailsTF에 대한 rect가 필요합니다. rectForRowAtIndexPath는 셀에있는 텍스트 필드가 아닌 셀의 rect를 반환합니다. – 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에서 프레임의 모든보기가 고정되어 있습니다. 따라서 수 없습니다 이러한 프레임을 수정하십시오. 셀에 대해 설정 한 프레임은 [cell reloadData]이 자동으로 호출되면 복원됩니다.

init 방법으로보기를 올바르게 초기화 했습니까?

"myCustomCell" 클래스의 "loadsubviews"메소드를 그냥 오버라이드하십시오.

이 방법에서 하위보기에 대한 CGRect를 인쇄합니다. 프레임이 올바르지 않으면 init 메서드에서보기를 초기화 할 때 문제가 발생해야합니다.