开发者

unable to get title bar and navigation button items

开发者 https://www.devze.com 2023-03-03 01:03 出处:网络
I have added a new file to my project in that i am creating the screens programatically and i used following code to create a grouped table view with a tit开发者_StackOverflowle bar & 2 buttons on

I have added a new file to my project in that i am creating the screens programatically and i used following code to create a grouped table view with a tit开发者_StackOverflowle bar & 2 buttons on title bar, but its creating only grouped table but not title bar y it is so, can any one help me thanx in advance

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Add Item";
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] 
                                              initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
                                              target:self action:@selector(cancel_Clicked:)] autorelease];

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
                                               initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
                                               target:self action:@selector(save_Clicked:)] autorelease];

    self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];



    tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 415)style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
}


UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
                                   initWithTitle:@"+"
                                   style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:@selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;

[journeylist.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@"listIcon-H.png"] tag:1];
journeylist.navigationItem.title =@"Journey List";

NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
self.viewControllers = controllers;

Try this.


Your table frame is CGRectMake(0, 0, 320, 415) so top left, you'll need to leave room for the title bar say CGRectMake(0, 40, 320, 415).


I think you have to present it like this.

SomeViewController *controller = [[SomeViewController alloc]
                                initWithNibName:@"SomeViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
                             initWithRootViewController:controller];
navController.navigationBar.tintColor = [UIColor grayColor];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[controller release];

Edit

When you are showing that controller with table view you have to frist add it to a navigation controller in order to show the navigation bar.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号