我问
[self presentModalViewController:searchRegionController animated:YES];
之后我尝试通过
添加NavigationController self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)] autorelease];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelAdd:)] autorelease]
self.navigationItem.titleView = someView;
答案 0 :(得分:2)
所以这样做 在searchRegionController类
中-(void)viewDidLoad
{
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:naviBarObj];
UIBarButtonItem *rightBarButtonItem =[[[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)] autorelease];
UIBarButtonItem *leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelAdd:)] autorelease];
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
navigItem.rightBarButtonItem = rightBarButtonItem;
navigItem.leftBarButtonItem = leftBarButtonItem;
naviBarObj.items = [NSArray arrayWithObjects: navigItem,nil];
}
希望这会有所帮助。
答案 1 :(得分:0)
试试这个:
-(void)someAction
{
ViewController *object = [ViewController]alloc]initWithNibName:@"NibName" bundle:[NSBundle mainBundle];
UINavigationController *navController = [UINavigationCOntroller]alloc]initWithRootViewController:object];
[self presentModalViewController:navController animated:YES];
[object release];
[navController release];
}
在ViewController的viewDidLoad
中执行:
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)] autorelease];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelAdd:)] autorelease]
self.navigationItem.titleView = someView;