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