2013-03-04 38 views
0

在我的应用程序中,我试图从一个TableViewCell导航到一个新的视图,但我不知道如何。你能帮帮忙吗?我正在使用Xcode 4.6。和.xib,没有故事板。我对编码非常陌生,所以请尽可能简单地解释它!这里是我所尝试过的,请纠正我:如何从TableViewCell推送新视图?

- (void)viewDidLoad 
{ 
tableData = [[NSArray alloc] initWithObjects:@"aaoversikt1", @"Paul", @"George", @"Ringo", nil]; 
[super viewDidLoad]; 
UILabel *nav_title1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 10, 220, 25)]; 
nav_title1.font = [UIFont fontWithName:@"Arial-BoldMT" size:18]; 
nav_title1.textColor = [UIColor whiteColor]; 
nav_title1.adjustsFontSizeToFitWidth = NO; 
nav_title1.textAlignment = NSTextAlignmentCenter; 
nav_title1.text = @"Ålesund"; 
nav_title1.backgroundColor = [UIColor clearColor]; 
self.navigationItem.titleView = nav_title1; 
} 

#pragma mark - TableView Data Source methods 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section; 
{ 
return [tableData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
UITableViewCell *cell = nil; 

static NSString *CellIdentifier = @"Cell"; 

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; 

return cell; 
} 

#pragma mark - TableView Delegate methods 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
AAOversiktViewController *aaoversikt1 = [[AAOversiktViewController alloc] initWithNibName:@"AAOversiktViewController" bundle:nil]; 
[self.navigationController pushViewController:aaoversikt1 animated:YES]; 
} 

谢谢!

+0

看起来你已经实现了didSelecdtRowAtIndexPath:正确。你看到什么问题?请注意,创建aaoversikt1后,你通常会与有关所选小区的信息进行配置。 – GoZoner 2013-03-04 18:21:48

回答

0

从第一眼我要说的是,问题的关键在于你的[self.navigationController pushViewController]方法中。您是否在应用程序委托或根视图控制器中启动了应用程序中的导航控制器?

如果不是我会建议:

[self presentViewController:aaoversik1 animated:YES completion:NULL]; 

如果你是想通过导航堆栈推,让你有一个后退按钮然后我会看看如何实现一个UINaviationController。

否则可以创建自定义后退按钮和用同样的方法在这篇文章呈现根视图控制器(未完全recomended如使用的UINavigationController干净多)。

让我知道这是否有任何帮助,T