2011-09-19 33 views
0

在我的iphone應用程序中我有這個pb:Application tried to push a nil view controller on target <UINavigationController: 我有一個視圖控制器包含一個tableview,我希望如果一行被選中一個其他視圖控制器是顯示。 這裏是我的代碼:應用程序試圖推動一個無視圖控制器的目標<UINavigationController

在RecherchePartenaireViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row==3){ 
     NSLog(@"RecherchePartenaireDistanceViewController..."); 

     recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc] init]; 

     self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController; 
     [self.navigationController pushViewController:recherchePartenaireDistanceViewController animated:YES]; 
     [recherchePartenaireDistanceViewController release]; 
    } 
} 

在RecherchePartenaireDistanceViewController.h:

@class RecherchePartenaireViewController; 

@interface RecherchePartenaireDistanceViewController : UIViewController { 

    RecherchePartenaireViewController *recherchePartenaireViewController; 
} 

@property (nonatomic, retain) IBOutlet RecherchePartenaireViewController *recherchePartenaireViewController; 
@end 

和RecherchePartenaireDistanceViewController.m

#import "RecherchePartenaireDistanceViewController.h" 
#import "RecherchePartenaireViewController.h" 

@implementation RecherchePartenaireDistanceViewController 


@synthesize recherchePartenaireViewController; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
    [recherchePartenaireViewController release]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

問題出在哪裏?我真的看不到它。請heeelp ....

回答

1

嘗試使用此:

- (void)dealloc 
{ 
    [recherchePartenaireViewController release]; 
    [super dealloc]; 

} 

代替

- (void)dealloc 
{ 
    [super dealloc]; 
    [recherchePartenaireViewController release]; 
} 
+0

與此沒有什麼變化.. – Gabrielle

0

如果RecherchePartenaireDistanceViewController與下面的語句在初始化廈門國際銀行界面比使用,

recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc] initWithNibName:@"RecherchePartenaireDistanceViewController" bundle:nil]; 

比將其推送到導航控制器。

+1

還是同樣的問題:((( – Gabrielle

+0

如果不指定XIB文件(即只需要調用'init'),那麼視圖控制器會自動尋找一個與 – deanWombourne

+0

我仍然有問題,嵌套的推動動畫可能導致損壞的導航欄 在意外的狀態下完成導航轉換導航欄子視圖樹可能會損壞 無法將自我添加爲子視圖,任何幫助將不勝感激 –

1

我想我明白你在做什麼,但我不明白你想達到什麼目的!你有一個包含另一個視圖控制器的ViewController?

RecherchePartenaireDistanceViewController包含RecherchePartenaireViewController

我認爲它是一個IBOutlet您使用的是廈門國際銀行文件填充它。

我能想到的唯一情況是在xib文件中創建RecherchePartenaireDistanceViewController時出現問題。

你怎麼在控制檯中看到,如果你這樣做:

NSLog(@"controller : %@", recherchePartenaireDistanceViewController); 

只是將它添加到導航控制器之前?

PS

這條線的目的是什麼?

self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController; 
相關問題