LoginSignup
3
3

More than 5 years have passed since last update.

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

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