无法获得标题栏和导航按钮项

时间:2011-05-06 05:15:41

标签: iphone objective-c titlebar

我已经在我的项目中添加了一个新文件,因为我以编程方式创建了屏幕,并使用以下代码创建了一个带有标题栏&标题栏上有2个按钮,但是它只创建了分组表而不是标题栏y是这样的,任何人都可以提前帮助我吗

- (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];
}

3 个答案:

答案 0 :(得分:0)

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;

试试这个。

答案 1 :(得分:0)

我认为你必须这样呈现。

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

修改

当您使用表格视图显示该控制器时,您必须将其添加到导航控制器以显示导航栏。

答案 2 :(得分:0)

您的桌架位于CGRectMake(0, 0, 320, 415)左上角,您需要为标题栏留出空间说CGRectMake(0, 40, 320, 415)