iOS - didSelectRowAtIndexPath 导致应用程序崩溃

标签 ios uitableview ios6 ios7

我有一个很奇怪的问题,我不明白。 我有一个 UITableView,当我点击一行时它会导致崩溃。

self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self; <-- If I remove this, no crash caused
self.tableView.dataSource = self;

有趣的是,我在 didSelectRowAtIndexPath 中根本没有任何代码,而且仍然崩溃? 日志并没有说明太多,我得到了 (lldb) 但是当进一步查看时,我从调试器中得到了这个。

[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]是什么原因?我不明白如何解决这个问题。

Thread 1, Queue : com.apple.main-thread
#0  0x02b1909f in objc_msgSend ()
#1  0x01afb285 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#2  0x01afb4ed in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()
#3  0x025055b3 in __NSFireDelayedPerform ()
#4  0x034f9376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#5  0x034f8e06 in __CFRunLoopDoTimer ()
#6  0x034e0a82 in __CFRunLoopRun ()
#7  0x034dff44 in CFRunLoopRunSpecific ()
#8  0x034dfe1b in CFRunLoopRunInMode ()
#9  0x03b387e3 in GSEventRunModal ()
#10 0x03b38668 in GSEventRun ()
#11 0x01a4bffc in UIApplicationMain ()
#12 0x000125bd in main at /Users/damianmendez/dev/trigd/jagodu-ios/Jagodu/Jagodu/main.m:16
#13 0x03210725 in start ()

有人有什么建议吗? 谢谢。

编辑: 在像@Phillip Millis 这样的启用僵尸之后也告诉我,我得到了这个:

*** -[RefineSearchViewController tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x9d24030

更新:

添加 RefineSearchViewController(它有一个 UITableView)的代码

RefineSearchViewController *refineSearchController = [[RefineSearchViewController alloc] initWithTransparentViews];
refineSearchController.parentDelegate = self.parentDelegate;

CGRect searchFrame = refineSearchController.view.frame;
searchFrame.origin.y = titleLabel.frame.origin.y + titleLabel.frame.size.height + 5;
refineSearchController.view.frame = searchFrame;

[self.refineSearchContainer addSubview:refineSearchController.view];    
[self.view addSubview:self.refineSearchContainer];

RefineSearchViewController 初始化代码

-(RefineSearchViewController*)init {
    self = [super init];

    if (self) {
        JoDModel *model = [JoDModel defaultModel];

        self.title = @"Search profile";
        _propertyNames = model.searchProfilePropertyNames;
        _properties = model.searchProfileProperties;
        _doneInvocation = nil;
        _isRefineSearch = NO;
        _transparentViews = NO;
    }

    return self;
}

-(RefineSearchViewController*)initWithTransparentViews {
    self = [self init];

    if (self) {
        _transparentViews = YES;
    }

    return self;
}

-(void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.titleShadow.hidden = !_addShadow;

    JoDModel *model = [JoDModel defaultModel];

    UIBarButtonItem *doneButton;

    if (_isRefineSearch) {
        doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Search" style:UIBarButtonItemStylePlain target:self action:@selector(done)];
        _keyboardBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, model.keyboardHeight)];
        _keyboardBg.backgroundColor = [UIColor blackColor];
        [self.view addSubview:_keyboardBg];
    } else {
        doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Search" style:UIBarButtonItemStylePlain target:self action:@selector(performSearch)];
    }

    self.navigationItem.rightBarButtonItem = doneButton;

    // When entering this view controller, the user will probably make a new search soon, therefore it's important to update the geo location
    if (model.shareMyLocation) {
        JoDAppDelegate *appDelegate = (JoDAppDelegate*)[UIApplication sharedApplication].delegate;
        [appDelegate updateLocation];
    }
}

-(void)dealloc {
    self.tableView = nil;
    _propertyNames = nil;
    _properties = nil;
    _doneInvocation = nil;
    _titleShadow = nil;
    _keyboardBg = nil;
}

最佳答案

您正在将 RefineSearchViewController 创建为局部变量。假设您的项目使用 ARC,当该引用超出范围(创建它的方法结束)时,它将被释放。

在创建它的 View Controller 中创建一个强大的属性并将其分配给它。

关于iOS - didSelectRowAtIndexPath 导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612330/

相关文章:

ios - 如何在表格 View 单元格内的 ImageView 上设置 cornerRadius

iphone - 支持旧的 iOS 版本和设备

ios - 水平条的 CorePlot 垂直滚动

ios - 显示多个本地通知而不创建新通知

ios - 使用 Storyboard "UIViewController-ZWG-5q-24I"中的标识符 "Main"实例化 View Controller ,但没有获得 UITableView。

ios - UItableview 中的多个部分的多项选择

ios - UISearchController 保留问题

ios - 将 UITableView 的高度调整为仅适合总内容大小所需的高度

ios6 - 底部的 UIToolbar 在 Retina 4 模拟器中不起作用

ios - 如何最好地处理核心数据 + iOS 状态恢复?