加载了笔尖,但没有得到一个UITableView

我一直在YouTube上关注本教程( 第1 部分和第2部分 )。

我已经完成了两个video,并使用以下代码将视图控制器与父视图控制器连接起来:

- (IBAction)searchButtonClicked:(id)sender { NSLog(@"It works."); SearchViewController *searchViewControl = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchControllerNav"]; [self presentViewController:searchViewControl animated:YES completion:nil]; } 

这个代码确实有效,因为这是我用于其他模式视图控制器的相同格式,所以我知道这不是问题。

无论如何,当我点击视图控制器中的searchbutton,它应该popupSearchViewController 。 然而,该应用程序崩溃,而是给了我这个错误消息:

 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "jp7-vt-IdA-view-Jer-xW-qlD" nib but didn't get a UITableView.' 

我正在使用这个应用程序的故事板。

有什么我失踪? 先谢谢你。

一个侧面的问题:我也得到一个警告,说只要显示isFiltered == YES Comparison between pointer and integer ('BOOL *' (aka 'signed char *') and 'int') isFiltered == YES比较。 有没有解决它?

这是SearchViewController的代码:

SearchController.h

 #import <UIKit/UIKit.h> @interface SearchViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate> { } - (IBAction)cancelButtonTapped:(id)sender; @property (weak, nonatomic) IBOutlet UISearchBar *mySearchBar; @property (weak, nonatomic) IBOutlet UITableView *myTableView; @property (nonatomic, strong) NSMutableArray *itemsInCloudApp; @property (nonatomic, strong) NSMutableArray *filteredList; @property BOOL *isFiltered; @end 

SearchViewController.m

 #import "SearchViewController.h" @interface SearchViewController () @end @implementation SearchViewController @synthesize mySearchBar, myTableView, itemsInCloudApp, filteredList, isFiltered; - (void)viewDidLoad { [super viewDidLoad]; // Set title. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; titleLabel.text = @"Search"; titleLabel.adjustsFontSizeToFitWidth = YES; titleLabel.clipsToBounds = YES; titleLabel.numberOfLines = 1; titleLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:18]; titleLabel.textColor = [UIColor blackColor]; titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight; titleLabel.textAlignment = NSTextAlignmentCenter; [titleLabel sizeToFit]; self.navigationItem.titleView = titleLabel; // Alloc and init list. itemsInCloudApp = [[NSMutableArray alloc]initWithObjects:@"http://www.apple.com/", @"http://www.trijstudios.com/", @"http://www.google.com/", @"http://www.squarespace.com/", @"http://www.youtube.com/", nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. if (isFiltered == YES) { return [filteredList count]; } else { return [itemsInCloudApp count]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // Configure the cell... if (isFiltered == YES) { cell.textLabel.text = [filteredList objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [filteredList objectAtIndex:indexPath.row];; } else { cell.textLabel.text = [itemsInCloudApp objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [itemsInCloudApp objectAtIndex:indexPath.row]; } return cell; } -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if (searchText.length == 0) { // Set bollean flag isFiltered = NO; } else { // Set boolean flag isFiltered = YES; // Alloc and init our fliteredData filteredList = [[NSMutableArray alloc] init]; // Fast enumeration for (NSString *name in itemsInCloudApp) { NSRange nameRange = [name rangeOfString:searchText options:NSCaseInsensitiveSearch]; if (nameRange.location != NSNotFound) { [filteredList addObject:name]; } } } // Reload tableView [myTableView reloadData]; } -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [mySearchBar resignFirstResponder]; } - (IBAction)cancelButtonTapped:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } @end 

注意:为了适应我的需求,我做了一些编辑。

你有没有尝试改变@interface SearchViewController : UITableViewController@interface SearchViewController : UIViewController

我强烈怀疑,或者你没有附加你的UITableview在XIB视图或您的类应派生UIViewController而不是UITableviewController类..

我有一个类似的错误。 我可以用Dinesh的build议来解决这个问题,但是我不喜欢这个,因为我担心会有一些意想不到的后果。

我想到的是,当我看到故事板中的场景层次结构时,我注意到我有这个结构(对不起,我不知道如何格式化 – 它应该是一个树结构):

 View Controller View Table View 

当我拿出坐在中间的景观时,我的问题就消失了。 但是,在此之前,您需要删除视图与视图控制器或表视图之间可能存在的任何sockets。 在确定这些消失后,请按照以下最后步骤操作:

  1. 拖动表视图,以便它是视图控制器的直接后裔。
  2. 删除视图
  3. 命令 – 从视图控制器拖到表视图,从而在两者之间直接创build一个新的出口。

另外,将.h文件作为UITableView的子类(而不是UIView )。

无论如何,这解决了我的问题。 如果有人遇到这个问题,我希望它有帮助。

对于你侧面的问题重新警告,警告来,因为你已经BOOL被筛选为一个指针。

对于你的第一个问题,你需要检查故事板 。 我相信你的文件所有者的 观点是连接到一个UIView 。 为了解决这个问题,你必须拖动UITableView并且视图必须连接到UITableView

对于你的第二个问题,声明BOOL

 @property(assign,nonatomic) BOOL isFiltered; 

我用一个简单的愚蠢的错误构buildiOS7通用应用程序时遇到了这个问题:我只构build了iPhone应用程序的一部分,但将scheme设置为iPad模拟器。 得到错误后,看到这里,我看到了我的错误,切换到iPhone的scheme,应用程序运行适当的故事板适当的模拟器。 希望有所帮助。