本文介绍了在objective-C中以编程方式为tableView创建导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式为我的表视图控制器类创建导航栏,请你帮忙吗?
我无法解决它!
I want to create navigation bar for my table view controller class programmatically would you please help me?I couldn't fix it!
提前致谢!
我是iOS编程的新手!
Thanks in advance!I'm really new to iOS programming!
这是我的表视图控制器类的代码
here is the code for my table view controller class
@implementation CheckedInOut
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
推荐答案
您没有为表视图控制器创建导航栏,您应该做的是创建导航控制器并将表视图控制器设置为其根
You dont create a navigation bar for a table view controller, what you should do is create a navigation controller and set the table view controller as its root
UITableViewController *myTableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:myTableViewController];
//use the navigation controller here instead of how you had used the table view controller
这篇关于在objective-C中以编程方式为tableView创建导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!