iphone - Access parent view from custom cell -
how can access uiview in have uitableview, custom cells inside table. cant find method that. thanks
you can add instance variable points uitableview , set when creating/configuring cell (e.g. in tableview:cellforrowatindexpath:). make sure cell not retain tableview though. knowing cell’s tableview, call [parenttableview superview] access uitableview’s parent view:
@interface propertylistingcell : uitableviewcell { __weak id parenttableview; } - (void) setparenttableview:(uitableview*)tv; // parenttableview = tv; in uitableviewcontroller implementation:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //dequeue/create , configure custom cell here [cell setparenttableview:tableview]; return cell; } update:
if you're using recent xcode (at least 4.3) can add
@property (weak) uitableview *parenttableview; // use unsafe_unretained instead of weak if you're targeting ios 4.x to @interface section of uitableviewcell's subclass. then, when you're creating cell (in tableview:cellforrowatindexpath:) set property accordingly:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { // ... //dequeue/create , configure custom cell here // ... cell.parenttableview = tableview; return cell; } and in cell class call self.parenttableview access tableview cell belongs to.
Comments
Post a Comment