UITableView and UITableViewCell in different iOS versions of hierarchical relationships

Source: Internet
Author: User

This is the first blog in my life, excitement, excitement, haha!!!

UITableView a control that is very common in iOS, in general the few proxy methods that must be implemented will suffice for us to implement some simple interfaces. But sometimes a sudden encounter with a question about tableview will make small white like me at a loss.

-(Nsindexpath *) Getindexpath: (ID) sender

{

UIButton *btn = ((UIButton *) sender);

UITableViewCell *cell = (UITableViewCell *) [[btn Superview] superview];

return [Self.tableview Indexpathforcell:cell];

}

Sender is a control added to the cell, so why two superview, because there is actually a layer of contentview between the cell and its child controls. So it is accurate to say that the child control of the cell should be Contentview, while the Contentview child control is sender. This is the case before iOS7, after IOS7, there is a scrollview between the cell and Contentview, so the above code should be changed to UITableViewCell *cell = (uitableviewcell*) [[[ BTN Superview] Superview] superview];

So in IOS7 and iOS8.0 seems to be able, but the back of the 8.3 is not, as for why, I do not understand now (which the great God know, remember to tell me AH). But I found another way to get the cell on the Internet.

-(Nsindexpath *) Getindexpath: (ID) sender

{

UIView *view = sender;

while (view! = Nil &&![ View Iskindofclass:[uitableviewcell class]) {

view = [view Superview];

}

UITableView *cell = (UITableView *) view;

return [Self.tableview Indexpathforcell:cell];

}

Real for any layer of hierarchical relationship, haha, really domineering.

UITableViewCell Superview Get UITableView, this is iOS7 before, 7 after the middle also a layer of uitableviewwrapperview.

First blog, slightly short, rough, you are welcome to advise

UITableView and UITableViewCell in different iOS versions of hierarchical relationships

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.