Можно добавить переменную экземпляра, которая указывает на UITableView, и установить ее при создании / настройке ячейки (например, в tableView: cellForRowAtIndexPath :). Убедитесь, что ваша ячейка не сохраняет tableView, хотя.
Зная tableView вашей ячейки, вызовите [parentTableView superView] для доступа к родительскому представлению UITableView:
@interface PropertyListingCell : UITableViewCell {
__weak id parentTableView;
}
- (void) setParentTableView:(UITableView*)tv; // parentTableView = tv;
В реализации UITableViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//dequeue/create and configure your custom cell here
[cell setParentTableView:tableView];
return cell;
}
UPDATE:
Если вы используете недавний XCode (по крайней мере 4.3), вы можете просто добавить
@property (weak) UITableView *parentTableView; // use unsafe_unretained instead of weak if you're targeting iOS 4.x
в @interface
раздел вашего подкласса UITableViewCell. Затем, когда вы создаете ячейку (в tableView:cellForRowAtIndexPath:
), установите это свойство соответствующим образом:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
//dequeue/create and configure your custom cell here
// ...
cell.parentTableView = tableView;
return cell;
}
И в вашем классе ячеек вызовите self.parentTableView
для доступа к таблице. Эта ячейка принадлежит.