问题描述:
创建了一个视图CategoryTableView,继承UIView。CategoryTableView包含了一个UITableView。我将CategoryTableView 作为子类添加到HomeViewController 中,HomeViewController 是UIViewController的子类。目前,我需要在didSelectRowAtIndexPath 执行时推入一个新的controller。但是在CategoryTableView中怎么推入或显示另一个视图控制器?
CategoryTableView.m
parent.m
创建了一个视图CategoryTableView,继承UIView。CategoryTableView包含了一个UITableView。我将CategoryTableView 作为子类添加到HomeViewController 中,HomeViewController 是UIViewController的子类。目前,我需要在didSelectRowAtIndexPath 执行时推入一个新的controller。但是在CategoryTableView中怎么推入或显示另一个视图控制器?
不能在CategoryTableView去导航控制器。
解决方案:
CategoryTableView.h
1
|
@property
(
retain
,
nonatomic
) parentViewController *parent;
//create one property for parent view like this
|
CategoryTableView.m
1
2
3
4
5
6
7
8
|
@sythesize
parent;
- (
void
)tableView:(
UITableView
*)tableView didSelectRowAtIndexPath:(
NSIndexPath
*)indexPath
{
[parent.navigationController . . .];
// preform action
//OR..
[parent presentModalViewController: . . .];
// present modal view
}
|
parent.m
1
2
3
4
|
//while calling your CategoryTableView assign self to your parent object
CategoryTableView *tblView = [CategoryTableView alloc] init];
tblView.parent =
self
;
|