我在執行上的iPhone應用程序的searchdisplay控制器點擊時崩潰,但是當我嘗試點擊搜索欄上(試了幾次之後)應用上的UISearchBar(searchDisplayController)
Thread 1: EXC_BAD_ACCESS (code=1, address=0x30000008)
將達到以下錯誤
我的代碼片段如下:
- (void)viewDidLoad
{
//Setting up the search bar for search display controller
UISearchBar *tempBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 34, 320, 44)];
self.sBar = tempBar;
[tempBar release];
self.sBar.delegate = self;
self.sBar.tintColor = [UIColor colorWithHexString:@"#b6c0c7"];
self.sBar.placeholder = @"Search DM friends";
self.searchDisplayController = [[[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self]autorelease];
[self setSearchDisplayController:searchDisplayController];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
self.searchDisplayController.searchResultsTableView.delegate = self;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 78)]autorelease];
headerView.backgroundColor = [UIColor colorWithHexString:@"#ebe7e6"];
if (tableView != self.searchDisplayController.searchResultsTableView){
//Search
UILabel *tagFriendsTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 320, 16)];
tagFriendsTitle.font = [UIFont boldSystemFontOfSize:14];
tagFriendsTitle.backgroundColor = [UIColor clearColor];
tagFriendsTitle.text = @"Who should see this? Tag them!";
[headerView addSubview:tagFriendsTitle];
//THIS IS WHERE I GET MY EXC_BAD_ACCESS error
[headerView addSubview:self.sBar];
[tagFriendsTitle release];
}
return headerView;
}
我不知道這是我的代碼部分導致了錯誤,但似乎日在我嘗試將其添加到標頭子視圖時,在從內存中釋放sBar?但我不確定爲什麼我需要在發生這種情況之前多次點擊搜索欄。
這是它的外觀在iPhone中,headerview的搜索欄形式部分
self.sBar它是保留還是分配屬性? –
我正在使用retain @property(nonatomic,retain)UISearchBar * sBar – Zhen