0

iPhone アプリに searchdisplay コントローラーを実装していますが、検索バーをクリックしようとすると次のエラーが発生します (数回試行した後)。

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 での外観です。検索バーはヘッダービューの一部を形成します。

ここに画像の説明を入力

4

2 に答える 2

3

製品に移動>スキームの編集> nszombieオブジェクトを有効にして、そこにある問題を確認してください

于 2012-05-22T14:33:06.473 に答える
1

これが割り当てプロパティである場合は、おそらく保持プロパティに変更する必要があります。deallocと でプロパティを nilに設定することを忘れないでくださいviewDidUnload

于 2012-05-22T14:34:29.243 に答える