我的以下搜索工作正常,但是我想将此代码添加到另一个使用情节提要的项目中。UIViewcontroller 工作正常,甚至通过 JSON 从数据库返回数据,但是我不断收到此错误
*由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView 返回一个单元格:cellForRowAtIndexPath:”
我在情节提要上添加了导航控制器和 Uiviewcontroller,还添加了表格和自定义单元格
我还在 UIviewcontroller 中创建了 searchbar 和 searchbar-controllers 出口,并将它们拖放到情节提要上并将它们链接起来
我不知道为什么当我在uisearchbar上执行搜索时,立即抛出上面的错误
searchbarcontroller 从 uitableview 接收其数据源
这是部分代码
`#import <UIKit/UIKit.h>
@interface MyController : UIViewController < UITableViewDelegate, UITableViewDataSource> {
UITableView *myTable;
UINib *myCell;
//Vars to hold json data
NSMutableArray *ids;
NSMutableArray *name;
NSMutableArray *price;
NSMutableArray *place;
NSMutableArray *thumb;
NSMutableArray *description;
//Searchbar stuff
IBOutlet UISearchBar *mySearchBar;
IBOutlet UISearchDisplayController *searchController;
// The saved state of the search UI if a memory warning removed the view.
NSString *savedSearchTerm;
NSInteger savedScopeButtonIndex;
NSMutableArray *searchedID;
NSMutableArray *searchedName;
NSMutableArray *searchedPrice;
NSMutableArray *searchedLocation;
NSMutableArray *searchedThumbs;
NSMutableArray *description;
}
@property (nonatomic, retain) IBOutlet UITableView *myTable;
@property (nonatomic, retain) IBOutlet UISearchDisplayController *searchController;
@property (nonatomic, retain) IBOutlet UISearchBar *mySearchBar;
@property (nonatomic, retain) NSMutableArray *ids;
@property (nonatomic, retain) NSMutableArray *name;
@property (nonatomic, retain) NSMutableArray *price;
@property (nonatomic, retain) NSMutableArray *place;
@property (nonatomic, retain) NSMutableArray *thumb;
@property (nonatomic, retain) NSMutableArray *description;
@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;
@property (nonatomic, retain) NSMutableArray *searchedID;
@property (nonatomic, retain) NSMutableArray *searchedName;
@property (nonatomic, retain) NSMutableArray *searchedPrice;
@property (nonatomic, retain) NSMutableArray *searchedLocation;
@property (nonatomic, retain) NSMutableArray *searchedThumbs;
@property (nonatomic, retain) NSMutableArray *searchedDescription;
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end
MyController.m file
#import "MyController.h"
@implementation myController
@synthesize myTable;
@synthesize data, searcheddata
@synthesize savedSearchTerm, savedScopeButtonIndex, searchWasActive;
//Add the search bar
#pragma mark -
#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 (tableView == self.searchDisplayController.searchResultsTableView) {
return [self.searchedIds count];
} else {
return [self.ids count];
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCellID"];
if (!cell)
{
NSArray *topLevelItems = [myCell instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
[[cell titles] setText:[searchedTitles objectAtIndex:indexPath.row]];
[[cell prices] setText:[NSString stringWithFormat:@"%@", [searchedPrices objectAtIndex:indexPath.row]]];
[[cell locations] setText:[NSString stringWithFormat:@"%@", [searchedLocation objectAtIndex:indexPath.row]]];
//Set the image with async technology
[[cell thumbs] setImageWithURL:[NSURL URLWithString:[searchedThumbs objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
} else {
[[cell titles] setText:[title objectAtIndex:indexPath.row]];
[[cell prices] setText:[NSString stringWithFormat:@"%@", [price objectAtIndex:indexPath.row]]];
[[cell locations] setText:[NSString stringWithFormat:@"%@", [location objectAtIndex:indexPath.row]]];
//Set the image with async technology
[[cell thumbs] setImageWithURL:[NSURL URLWithString:[thumb objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
return cell;
}
`
[1]: http://i.stack.imgur.com/0ZNzq.png