不要在modalView上显示UINavigationController

时间:2012-02-09 09:59:18

标签: objective-c uinavigationcontroller modalviewcontroller

我问

[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;

2 个答案:

答案 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;