2011-03-24 73 views
3

我試圖創建一個導航stype應用程序,但我想自定義初始視圖,以便tableview不佔用整個框架,而是嵌入在一個子視圖中,所以我可以應用程序首次啓動時的一些標籤和圖像。RootViewController上的NSInternalInconsistencyException

我宣稱UIViewUITableView ivars在RootViewController.h,並添加它們作爲屬性與標準的「(nonatomic, retain) IBOutlet」標記;並在RootViewController.m,我合成了兩個,並添加代碼將它們設置爲nilviewDidUnload,並在dealloc發佈它們。 (努力成爲一名優秀的記憶管理公民。)我沒有添加任何其他代碼。編譯時沒有警告。當我試圖試駕應用程序,它與消息立即(和重複)墜毀:

*** Terminating app due to uncaught exception          

NSInternalInconsistencyException', 
reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the 
"RootViewController" nib but the view outlet was not set.' 

我已經連接兩者的觀點和我的RootViewController筆尖的tableview到文件的所有者;當我右鍵單擊對象圖中的文件所有者時,我將它們都列爲Outlet。當我右鍵單擊每個控件時,我將文件所有者視爲引用出口。

幫助!我該如何解決?

更新

// 
// RootViewController.m 
// rx2 
// 

#import "RootViewController.h" 


@implementation RootViewController 

/* I added these two lines */ 
@synthesize uiView; 
@synthesize uiTableView; 

#pragma mark - 
#pragma mark View lifecycle 


#pragma mark - 
#pragma mark Table view data source 

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 0; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

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

    // Configure the cell. 

    return cell; 
} 




#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    /* 
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
    */ 
} 


#pragma mark - 
#pragma mark Memory management 

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

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

- (void)viewDidUnload { 
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
    // For example: self.myOutlet = nil; 

/* I added these two lines */ 
    self.uiView = nil; 
    self.uiTableView = nil; 
} 


- (void)dealloc { 

/* I added these two lines */ 
    [uiView release]; 
    [uiTableView release]; 


    [super dealloc]; 
} 


@end 
+0

我把你的答案合併到你的問題中,你可能想編輯前言。請不要回復作爲答覆,並考慮採取社區給你的建議:) – 2011-03-24 14:14:28

+0

我發佈了回覆作爲答案,因爲我無法發佈回覆。我得到的建議是什麼?我已經檢查並重新檢查了nib文件,並且所有屬性都連接到文件的所有者。那麼解決這個問題的下一步是什麼? – Namhcir 2011-03-24 16:06:05

回答

1

這意味着,該RootViewController的的view屬性(從UIViewController繼承)沒有連接到筆尖文件的視圖。如果右鍵單擊對象圖中的文件所有者,那麼您會看到它的view插座連接到佈局中的視圖,如附加的截圖所示。

the file's owner's view property connected to a view

您可以發佈您RootViewController.h文件作爲編輯你的問題?

+0

是的,我看到連接如下: – Namhcir 2011-03-24 12:30:45

+0

如下? :-) – CharlieMezak 2011-03-24 12:32:21

+0

文件的所有者具有爲我的實例變量屬性以及視圖屬性列出的插座; (對不起,我似乎無法按照您的方式剪切和粘貼圖像)... – Namhcir 2011-03-24 12:35:57

0

您只需將xib中的默認視圖連接到文件所有者即可。

+0

當我在RootViewController.xib文件中查看文件的所有者時,插座的圓圈填充在 – Namhcir 2011-03-24 12:38:00

+0

看視圖是否連接,如果已連接,則斷開連接並重新連接 – saadnib 2011-03-25 04:26:59

相關問題