0
我有以下搜索工作正常,但我想將此代碼添加到另一個使用故事板的項目。在UIViewController的好的工作,甚至從通過JSON數據庫返回的數據,但我不斷收到此錯誤故事板IOS6中的Uisearchbar和Searchcontroller
*終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「UITableView的數據源必須的tableView返回細胞:的cellForRowAtIndexPath:」
我已經加入導航控制器加的UIViewController上的腳本中,加入表和定製細胞以及
我也取得了搜索欄和搜索欄控制器outle在UIViewController中TS並被拖聯繫起來的故事板
我不知道爲什麼,當我執行上的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