1

我想以编程方式为我的表格视图控制器类创建导航栏,你能帮帮我吗?我无法修复它!

提前致谢!我对 iOS 编程真的很陌生!

这是我的表视图控制器类的代码

 @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
4

2 回答 2

4

您没有为表格视图控制器创建导航栏,您应该做的是创建一个导航控制器并将表格视图控制器设置为其根

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
于 2012-07-18T08:26:26.933 回答
0

这三行

ViewController *vc = [[ViewController alloc]init];// or UITableVC as which VC you have in your file
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];
    [self.window addSubview:navController.view]; // this is an important line if missed out dont show navController

应该在后面加上

 [self.window makeKeyAndVisible];

appDelegate.m didFinishLaunchingWithOptions方法中

于 2012-10-17T09:25:24.540 回答