大家好,我目前的搜索栏有问题。当我运行项目时,搜索栏出现并且一切正常,但是当我在搜索栏中实际输入时,它会在此处返回一个 sigabrt 错误:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
这是我的 viewcontroller.h:
@interface CollegeViewController : UIViewController <UITableViewDataSource, UITableViewDelegate,ADBannerViewDelegate>
{
IBOutlet UITabBar *tabBar1;
}
@property (nonatomic, strong) IBOutlet UITableView *tableView;
@property(nonatomic, retain) UITabBar *tabBar1;
@end
这是我的viewcontroller.m:
@interface CollegeViewController ()
@end
@implementation CollegeViewController {
NSArray *colleges;
NSArray *searchResults;
}
- (void)viewDidLoad
{
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
UIEdgeInsets inset = UIEdgeInsetsMake(5, 0, 0, 0);
self.tableView.contentInset = inset;
[super viewDidLoad];
self.navigationItem.title = @"List of Colleges";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
// Do any additional setup after loading the view.
College *college1 = [College new];
college1.name = @"Harvard University";
college1.collegeName = @"Harvard University";
college1.rank = @"#1";
college1.imageFile = @"01.jpg";
college1.sizeofCollegeCampus = @"210 acres";
college1.tuition = @"$38,480";
college1.numberofStudents = @"27,392";
college1.address = @"Massachusetts Hall, Cambridge, MA 02138";
college1.acceptanceRate = @"5.9%";
college1.phoneNumber = @"(617) 495-1000";
college1.majorPrograms = @"Economics, Political Science and Government, Psychology, English Language and Literature/Letters, and Social Sciences";
college1.website = @"www.harvard.edu/";
college1.isitIvyLeague = @"Yes";
college1.mascot = @"John Harvard";
college1.color = @"crimson";
college1.satScore = @"";
college1.actScore = @"";
college1.collegeNameCell = @"Harvard University";
college1.collegeRankCell = @"#1";
college1.collegePhotoCell = @"Harvard_Wreath_Logo_1.svg.png";
..............
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)
banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [colleges filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
} else {
return [colleges count];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
NSInteger rowIndex = indexPath.row;
UIImage *background = nil;
if (rowIndex == 0) {
background = [UIImage imageNamed:@"cell_top.png"];
} else if (rowIndex == rowCount - 1) {
background = [UIImage imageNamed:@"cell_bottom.png"];
} else {
background = [UIImage imageNamed:@"cell_middle.png"];
}
return background;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
College *college = [colleges objectAtIndex:indexPath.row];
UIImageView *collegeImageView = (UIImageView *)[cell viewWithTag:100];
collegeImageView.image = [UIImage imageNamed:college.collegePhotoCell];
UILabel *CollegeNameLabel = (UILabel *)[cell viewWithTag:101];
CollegeNameLabel.text = college.collegeNameCell;
UILabel *CollegeRankLabel = (UILabel *)[cell viewWithTag:102];
CollegeRankLabel.text = college.collegeRankCell;
if (tableView == self.searchDisplayController.searchResultsTableView) {
College *college = [colleges objectAtIndex:indexPath.row];
UIImageView *collegeImageView = (UIImageView *)[cell viewWithTag:100];
collegeImageView.image = [UIImage imageNamed:college.collegePhotoCell];
UILabel *CollegeNameLabel = (UILabel *)[cell viewWithTag:101];
CollegeNameLabel.text = college.collegeNameCell;
UILabel *CollegeRankLabel = (UILabel *)[cell viewWithTag:102];
CollegeRankLabel.text = college.collegeRankCell;
} else {
College *college = [colleges objectAtIndex:indexPath.row];
UIImageView *collegeImageView = (UIImageView *)[cell viewWithTag:100];
collegeImageView.image = [UIImage imageNamed:college.collegePhotoCell];
UILabel *CollegeNameLabel = (UILabel *)[cell viewWithTag:101];
CollegeNameLabel.text = college.collegeNameCell;
UILabel *CollegeRankLabel = (UILabel *)[cell viewWithTag:102];
CollegeRankLabel.text = college.collegeRankCell;
}
// Assign our own background image for the cell
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
// Display college in the table cell
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showCollegeDetail"]) {
CollegeDetailViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
indexPath = [self.tableView indexPathForSelectedRow];
destViewController.college = [colleges objectAtIndex:indexPath.row];
destViewController.hidesBottomBarWhenPushed = YES;
}
}
@end
有什么建议么?