アプリを実行すると、次のエラーが発生します。
キャッチされなかった例外「NSInternalInconsistencyException」が原因でアプリを終了しています。理由:「-[UITableViewController loadView]は「2-view-3」ペン先をロードしましたが、UITableViewを取得しませんでした。」
以下は私が使用しているコードです、
ViewController.h
@interface ViewController : UITableViewController <UISearchDisplayDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSArray *arForTable;
@property (nonatomic,strong) NSArray *arForSearch;
ViewController.m
@implementation ViewController
@synthesize arForTable = _arForTable;
@synthesize arForSearch = _arForSearch;
-(void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.arForTable = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"Pending",@"name",@"2",@"value",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Pent",@"name",@"22",@"value",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Pen",@"name",@"5",@"value",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Neon",@"name",@"7",@"value",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Spark",@"name",@"99",@"value",nil],
nil];
self.arForSearch = nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return (tableView == self.tableView)?self.arForTable.count:self.arForSearch.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
NSDictionary *dToAccess = (self.tableView==tableView)?[self.arForTable objectAtIndex:indexPath.row] : [self.arForSearch objectAtIndex:indexPath.row];
[(UILabel*)[cell viewWithTag:1] setText:[dToAccess valueForKey:@"name"]];
[(UILabel*)[cell viewWithTag:2] setText:[dToAccess valueForKey:@"value"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)filterContentForSearchText:(NSString*)str{
// for inCaseSensitive search
str = [str uppercaseString];
NSMutableArray *ar=[NSMutableArray array];
for (NSDictionary *d in self.arForTable) {
NSString *strOriginal = [d valueForKey:@"name"];
// for inCaseSensitive search
strOriginal = [strOriginal uppercaseString];
if([strOriginal hasPrefix:str]) {
[ar addObject:d];
}
}
self.arForSearch=[NSArray arrayWithArray:ar];
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
前もって感謝します