1

I have a customCell and add some button into cell.

SettingTableViewCell * cell = (SettingTableViewCell *)[[sender superview] superview];
NSIndexPath * path = [self.tableView indexPathForCell:cell];

How to understand the second sentence!

Thank you very much!

Akhilrajtr
  • 5,170
  • 3
  • 19
  • 30
user_name
  • 67
  • 7
  • second sentence is use for get [indexPath (about indexPath)](http://stackoverflow.com/questions/14765730/nsindexpath-item-vs-nsindexpath-row/14765781#14765781) of current cell. – iPatel Mar 19 '14 at 05:56

1 Answers1

1

Don't know what you trying to do. But I give explanation for this two line.

[sender superview] which means, you may click on button, that's why, you get this sender which placed on cell's contentview. Then again you call superview], So you can get superview of content view which is in cell. see below that view hierarchy.

----cell
-------ContentView
-------------Sender

NSIndexPath * path = [self.tableView indexPathForCell:cell];. This line will give indexPath for corresponding cell which is kept in tableview cell stack.

Mani
  • 17,549
  • 13
  • 79
  • 100
  • YES,I see!I do not understand the hierarchical relationship between them.Thanks! – user_name Mar 19 '14 at 06:03
  • That you cell have content view as subview and content view have button as subview. That's in view hierarchy. See this link to know more about view hierarchy. https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/CreatingViews/CreatingViews.html – Mani Mar 19 '14 at 06:06
  • When I customCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier [self addSubview:] and [self.contentView addSubview] Difference between the two? – user_name Mar 19 '14 at 06:10
  • You've asked some question, I answered for that. If you've another question, placed it separately. Ok. answer is I don't know but you can see this explanation in apple's doc `The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.` – Mani Mar 19 '14 at 06:18
  • https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006938-CH3-SW18 – Mani Mar 19 '14 at 06:20