问题描述
我的应用程式版面配置如下:
TabBarController(hold a) - > UINavController for Tab 1(hold a) - > MyOwnListViewController - > UINavController(modally)(hold a) - > ItemAddViewController - > AddItemToItemViewController
也许这不是很清楚,所以为了清楚起见,当应用程序启动时,我在选项卡1和 MyOwnListViewController
是可见的,然后我推+按钮,我以模块的方式到 ItemAddViewController
。从那里我pushViewController AddItemToItemViewController
。现在在这个视图控制器,我想得到一个引用 ItemAddViewController
。
您可以修改AddItemToItemViewController的init ***方法,并将它传递给您的ItemAddViewController。
EG:
在AddItemToItemViewController.h中:
@property(nonatomic,retain)UIViewController * parentController;
在AddItemToItemViewController.m中:
@synthesize parentController;
- (id)initWithParentController:(UIViewController *)controller {
self = [super init];
if(self){
self.parentController = controller;
}
return self;
}
- (void)dealloc {
[self.parentController release];
[super dealloc]
}
当在ItemAddViewController实例中调用控制器时:
UIViewController * controller = [[AddItemToItemViewController alloc] initWithParentController:self];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
I'm way in deep water here trying to get ahold of a vc.
My App layout looks like this:
TabBarController (holds a) -> UINavController for Tab 1 (holds a) -> MyOwnListViewController -> UINavController (modally) (holds a) -> ItemAddViewController -> AddItemToItemViewController
Maybe that wasn't very clear, so for clarity, when the app starts I'm on tab 1 and the MyOwnListViewController
is visible, then I push a + button in the navigation bar and I'm taken modally to the ItemAddViewController
. From there I pushViewController AddItemToItemViewController
. Now in this view controller I want to get a reference to ItemAddViewController
.
What would be the easiest way to get a reference to it?
You could modify the init*** method of your AddItemToItemViewController and pass it the reference on your ItemAddViewController.
E.G :
In AddItemToItemViewController.h :
@property (nonatomic, retain) UIViewController *parentController;
In AddItemToItemViewController.m :
@synthesize parentController;
-(id) initWithParentController:(UIViewController *) controller{
self = [super init];
if(self){
self.parentController = controller;
}
return self;
}
-(void) dealloc{
[self.parentController release];
[super dealloc];
}
When calling your controller inside your ItemAddViewController instance :
UIViewController *controller = [[AddItemToItemViewController alloc] initWithParentController:self];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
这篇关于Objective-C - 获取UIViewController引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!