本文介绍了如何将参数传递到iOS中的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UIViewController *theController = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
[self.navigationController presentModalViewController:theController animated:TRUE];
这是我显示视图的代码。我知道我可以使用app委托变量,但它更简洁,我可以以某种方式传递参数,理想情况下使用枚举。这可能吗?
Here's my code for showing my view. I know I can use app delegate variables, but it would be neater is I could pass a parameter in somehow, ideally using an enum. Is this possible?
推荐答案
只需为HelpViewController创建一个新的init方法,然后从那里调用它的超级init方法......
Just create a new init method for your HelpViewController and then call its super init method from there...
在HelpViewController.h中
In HelpViewController.h
typedef enum
{
PAGE1,
PAGE2,
PAGE3
} HelpPage;
@interface HelpViewController
{
HelpPage helpPage;
// ... other ivars
}
// ... other functions and properties
- (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle onPage:(HelpPage)page;
@end
在HelpViewController.m中
In HelpViewController.m
- (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle onPage:(HelpPage)page
{
self = [super initWithNibName:nibName bundle:nibBundle];
if(self == nil)
{
return nil;
}
// Initialise help page
helpPage = page;
// ... and/or do other things that depend on the value of page
return self;
}
并致电:
UIViewController *theController = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil onPage:PAGE1];
[self.navigationController presentModalViewController:theController animated:YES];
[theController release];
这篇关于如何将参数传递到iOS中的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!