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

发布于 2024-11-05 21:00:06 字数 1071 浏览 2 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

破晓 2024-11-12 21:00:06
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;

试试这个。

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.

清醇 2024-11-12 21:00:06

您的表格框架是 CGRectMake(0, 0, 320, 415),因此在左上角,您需要为标题栏留出空间,比如 CGRectMake(0, 40, 320, 415) 。

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).

缱绻入梦 2024-11-12 21:00:06

我认为你必须这样呈现它。

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

编辑

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文