2012-03-24 35 views
1

我在我的iOS應用程序標籤表視圖,但我不能運行應用程序,我在運行時出現此錯誤:嘗試使用iOS中的表視圖,收到錯誤

3/23/12 10:15:23.119 PM CodeCompanion: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "2-view-16" nib but didn't get a UITableView.' 
*** First throw call stack: 
(0x13bd052 0x154ed0a 0x1365a78 0x13659e9 0x2436ae 0xda5cb 0xf5b89 0xf59bd 0xf3f8a 0xf3e2f 0xf1ffb 0xf285a 0xdbfbf 0xdc21b 0xdd0f1 0x4bfec 0x51572 0x4b72b 0x3abc2 0x3ace2 0x3aea8 0x41d9a 0x12be6 0x138a6 0x22743 0x231f8 0x16aa9 0x12a7fa9 0x13911c5 0x12f6022 0x12f490a 0x12f3db4 0x12f3ccb 0x132a7 0x14a9b 0x2888 0x27e5) 

我的視圖控制器頭文件是如下:

#import <UIKit/UIKit.h> 

@class LanguageTableViewCell; 

@interface LanguagesViewController : UITableViewController { 

    NSArray *languages; 

} 

@property (nonatomic, retain) NSArray *languages; 

@end 

和我的執行文件是:

#import "LanguagesViewController.h" 
#import "LanguageTableViewCell.h" 

@implementation LanguagesViewController 

@synthesize languages; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"getting cell for row at index path: %i", [indexPath row]); 
    LanguageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"languageBase"]; 
    if (cell == nil) { 
     cell = [[LanguageTableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:@"languageBase"]; 
    } 
    [cell setName:[languages objectAtIndex:[indexPath row]]]; 
    return cell; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSLog(@"rows in section: %i is: %i", section, [languages count]); 
    return [languages count]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    NSLog(@"getting number of sections (1)"); 
    return 1; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [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, typically from a nib. 
    NSLog(@"view loaded, setting array"); 
    languages = [NSArray arrayWithObjects:@"Java", nil]; 
} 

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

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
    } else { 
     return YES; 
    } 
} 

@end 

我是很新,Xcode和objective- c,所以請提及任何可能出錯的地方。我已經將表視圖的ViewController設置爲我的上面的類,並且我沒有在xcode中收到任何錯誤或警告。表視圖是使用原型單元格的那些動態類型之一。如果我需要發佈單元格的類,我會的。

+1

將超類從UITableViewController更改爲UIViewController。 – CodaFi 2012-03-24 02:52:23

回答

0

通過看看你的錯誤信息,你正在使用一個nib文件「2-view-16」來佈局你的視圖,但它不包含UITableView(或者它沒有連接)。

LanguagesViewController繼承自UITableViewController,它正在尋找一個UITableView來控制哪個不存在。

如果您使用筆尖來設置視圖,則需要將UITableView添加到筆尖並將其設置爲您的LanguagesViewController的tableView。

+0

我正在使用故事板。對不起,我的無知,但那是不同的,對吧? – Greg 2012-03-24 02:57:06

+0

啊,對不起,我不熟悉故事板,所以我無法提供幫助。 – sampage 2012-03-24 02:59:37

+2

@sampage:tableView不是UITableViewController的暴露出口(足夠愚蠢),他必須創建他自己的,然後將它設置爲不僅作爲tableView,而且作爲視圖。 – CodaFi 2012-03-24 03:06:17

相關問題