iOS - didSelectRowAtIndexPath导致应用程序崩溃 [英] iOS - didSelectRowAtIndexPath causes crash in app
问题描述
我有一个我不明白的非常奇怪的问题。
我有一个 UITableView
,当我点击一行时会导致崩溃。
I have a very strange problem that I don't understand.
I have a UITableView
which causes a crash when I click on a row.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self; <-- If I remove this, no crash caused
self.tableView.dataSource = self;
有趣的是我内部没有代码 didSelectRowAtIndexPath
,还在崩溃吗?
日志说得不多,我得到(lldb)
但是当看得更远时,我从调试器得到了这个。
The funny thing is that I have no code at all inside didSelectRowAtIndexPath
, and is still crashes?
The log doesn't say much, I get (lldb)
but when looking a bit further, I got this from debugger.
[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
是什么原因?我不明白如何解决这个问题。
[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
is the cause? I dont understand how to solve this problem.
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 ()
任何人有什么建议吗?
谢谢。
Anyone has any suggestions? Thanks.
编辑:
启用像@Phillip Millis这样的僵尸告诉我,我得到了这个:
After enabled zombies like @Phillip Millis told me too, I got this:
*** -[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,那么当该引用超出范围(创建它的方法的结尾)时,它将被释放。
You are creating the RefineSearchViewController
as a local variable. Assuming your project uses ARC, it will then be deallocated when that reference goes out of scope (end of the method that created it).
在视图中创建一个强大的属性创建它并将其分配给它的控制器。
Make a strong property in the view controller that creates it and assign to that instead.
这篇关于iOS - didSelectRowAtIndexPath导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!