2013-03-04 37 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