Search code examples
uitableviewcell

How to get UITableViewStyle inside UITableViewCell


I had tried check inside cell backgroundView, but for both styles (UITableViewStylePlain, UITableViewStyleGrouped) were equal to NOT nil. There is whether any way to get UITableViewStyle from inside UITableViewCell?

SOLVED: I just added to cell constructor a variable of type UITableViewStyle and set it when created


Solution

  • Ideally, your cell shouldn't care what the style is.

    But if you must know, your best bet is to do something like this:

    UIView *tv = self;
    while (tv && ![tv isKindOfClass:[UITableView class]]) tv = tv.superview;
    UITableViewStyle style = [(UITableView *)tv style];