从UIView的子类中推入视图控制器

来源:互联网 发布:批量网页录入数据 编辑:程序博客网 时间:2024/05/16 06:14

原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1972

问题描述:

创建了一个视图CategoryTableView,继承UIView。CategoryTableView包含了一个UITableView。我将CategoryTableView 作为子类添加到HomeViewController 中,HomeViewController 是UIViewController的子类。目前,我需要在didSelectRowAtIndexPath 执行时推入一个新的controller。但是在CategoryTableView中怎么推入或显示另一个视图控制器?

不能在CategoryTableView去导航控制器。

解决方案:

CategoryTableView.h

@property (retain, nonatomic) parentViewController *parent; //create one property for parent view like this

CategoryTableView.m

@sythesize parent;- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    [parent.navigationController . . .]; // preform action    //OR..    [parent presentModalViewController: . . .]; // present modal view}

parent.m

//while calling your CategoryTableView assign self to your parent object    CategoryTableView *tblView = [CategoryTableView alloc] init];    tblView.parent = self;


原创粉丝点击