iphone - 单击 UISearchbar (searchDisplayController) 时应用程序崩溃

标签 iphone ios crash uisearchbar uisearchdisplaycontroller

我正在 iPhone 应用程序上实现搜索显示 Controller ,但是当我尝试点击搜索栏时(尝试几次后)会遇到以下错误

Thread 1: EXC_BAD_ACCESS (code=1, address=0x30000008)

enter image description here

我的代码片段如下:

- (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;

}

我不确定我的代码的哪一部分导致了错误,但是当我尝试将它添加到标题 subview 时,sBar 似乎从内存中释放了?但我不确定为什么我需要多次点击搜索栏才能发生这种情况。

这是它在 iPhone 上的样子,搜索栏构成标题 View 的一部分

enter image description here

最佳答案

转到产品>编辑方案>启用nszombie对象并查看那里有什么问题

关于iphone - 单击 UISearchbar (searchDisplayController) 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10704085/

相关文章:

iphone - 无限旋转图片背景UIImageView

ios - resizableImageWithCapInsets 图片总是错位?

vb.net - 使 VB.NET 程序崩溃的简单方法

android - 当我尝试开启蓝牙时,应用程式当机

iphone - 如何在 TabBar 中正确集成 InAppSettingsKit 与 Storyboard?

iphone - 在cocos2d中创建一个用于游戏开发的 "developer screen"

iphone - 是否可以将 UIBarButtonItem 作为单元格accessoryView?

iphone - 如何从 uitableviewcell 选择中设置 subview 的标题

iphone - EXC_BREAKPOINT 崩溃。可能越狱问题?

iphone - 从 iOS 的 URL 解析 XML 的最佳方法是什么?