0

tableViewCell textField の正しいフレームを取得できないのはなぜですか?

myCustomCell には leftDetailTF と rightDetailTF テキストフィールドがあります。

以下のログ ステートメントは、タップしたセル/テキスト フィールドに関係なく、同じ rect 座標を生成します。ログ: フレーム = {{470, 1}, {200, 24}}

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

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

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

4 に答える 4

0

配列を使用して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],........);
}
于 2012-11-27T06:54:38.663 に答える
0

スーパービューのスーパービューでサブビューのフレームを確認する場合は、これを使用できます。

  CGRect rect = [cell.rightDetailTF.superview convertRect:cell.rightDetailTF.frame toView:self.view];
NSLog(@"Rect:%@",NSStringFromCGRect(rect));
于 2012-11-27T06:58:17.160 に答える
0

つまり、iOSのUITableViewの場合、フレームはセル内のすべてのビューに対して固定されています。したがって、これらのフレームを変更することはできません。セルに設定したフレームが何であれ、が自動的に呼び出されると復元さ[cell reloadData]れます。

メソッドのビューを正しく初期化しましたinitか?

「myCustomCell」クラスの「loadsubviews」メソッドをオーバーライドするだけです。

このメソッドのサブビューのCGRectを印刷します。フレームが正しくない場合は、initメソッドでビューを初期化するときに問題が発生する必要があります。

于 2012-11-27T07:12:27.417 に答える
0

最初にセルのフレームを取得します...

CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath];

次に、右のテキスト フィールドのフレームを取得します...

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

次に、2 つを結合します。

CGRect resultFrame = CGRectMake(cellFrame.origin.x + rightDetailTFFrame.origin.x, cellFrame.origin.y + rightDetailTFFrame.origin.y, rightDetailTFFrame.size.width, rightDetailTFFrame.size.height);
于 2012-11-27T04:23:43.273 に答える