无法获取标题栏和导航按钮项目
我已向我的项目添加了一个新文件,因为我正在以编程方式创建屏幕,并使用以下代码创建带有标题栏和标题栏的分组表视图。标题栏上有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个。
Try this.
您的表格框架是 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 sayCGRectMake(0, 40, 320, 415)
.我认为你必须这样呈现它。
编辑
当您使用表格视图显示该控制器时,您必须首先将其添加到导航控制器才能显示导航栏。
I think you have to present it like this.
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.