如何将UIViewController实例传递给Custom UITableCell

时间:2016-04-27 04:24:29

标签: ios uitableview uiviewcontroller

我有一个视图控制器,它是HomeController。我在HomeController中添加了一个tableview。我在这个UITableView上添加了一个Custom Cell,其名称是HomeCategoryRow。所以我的搜索是我必须将HomeController实例传递给我的HomeCategoryRow类来完成我的工作。提前谢谢。

1 个答案:

答案 0 :(得分:0)

NSLog(@"The View Controller is: %@",_homeController); 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName: @"Main" bundle:[NSBundle mainBundle]]; 
AblumsController *myAlbum = [storyboard instantiateViewControllerWithIdentifier:@"AlbumsControllerIdentifier"]; // myAlbum.typeofParam=2; 
myAlbum.homeController = _homeController;//ADD THIS
[_homeController pushViewController:myAlbum animated:YES];

<强> AblumsController.h

@property (nonatomic, weak) id homeController;

@class HomeController;
@interface HomeTableViewController : UITableViewController
@property (nonatomic, weak) HomeController *homeController;

<强> AblumsController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCategoryRow *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.homeController = self.homeController
}

<强> HomeCategoryRow.h

@property (nonatomic, weak) id homeController;

@class HomeController;
@interface HomeCategoryRow : UITableViewCell
@property (nonatomic, weak) HomeController *homeController;

<强> HomeCategoryRow.m

#import "HomeController.h"