3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS7にしたらcellのインデックスが取れない問題が発生した

3
Posted at

経緯

iOS5,6でつくっていたアプリでiOS7のときだけcellに設置したボタンのindexが取得できなくなっていた。

元々の実装

superviewを決め打ちだった。

UITableViewCell *cell = (UITableViewCell *) [[[(UIButton *) sender superview] superview] superview];

改修

while文ぶん回して解決

- (void)pushButtonOnCell:(id)sender
{
    UIView *view = [(UIButton *) sender superview];
    while (![view isKindOfClass:[UITableViewCell class]]) {
        view = [view superview];
    }
    UITableViewCell *cell = (UITableViewCell *)view;
    int              row  = [self.calendarTable indexPathForCell:cell].row;
    NSLog(@"row = %d", row);
}

参考記事

indexPathForCell returns nil since ios7

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?