Ios UITableview重新加载数据时报告崩溃

Ios UITableview重新加载数据时报告崩溃,ios,uitableview,crashlytics,reloaddata,Ios,Uitableview,Crashlytics,Reloaddata,我从Crashlytics收到一份崩溃报告,它总是在同一个地方,但我无法复制崩溃 似乎只有iOS 9上的用户,而且只是偶尔出现。我不确定这是代码问题还是其他问题。最后一行提到缺少libdispatch.dylib,同样不确定是否相关 Crashlytics表示崩溃发生在MMDetailTableVC.m第1407行,即reloadData行 报道如下: Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000

我从Crashlytics收到一份崩溃报告,它总是在同一个地方,但我无法复制崩溃

似乎只有iOS 9上的用户,而且只是偶尔出现。我不确定这是代码问题还是其他问题。最后一行提到缺少
libdispatch.dylib
,同样不确定是否相关

Crashlytics表示崩溃发生在
MMDetailTableVC.m
第1407行,即
reloadData

报道如下:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000001

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib           0x20f0fae2 objc_msgSend + 1
1  CoreFoundation            0x2168b91b -[NSDictionary descriptionWithLocale:indent:] + 310
2  Foundation                0x21e77e2d _NSDescriptionWithLocaleFunc + 60
3  CoreFoundation            0x217091a3 __CFStringAppendFormatCore + 7986
4  CoreFoundation            0x21707255 _CFStringCreateWithFormatAndArgumentsAux2 + 80
5  CoreFoundation            0x2171f559 _CFLogvEx2 + 96
6  CoreFoundation            0x2171f9af _CFLogvEx3 + 118
7  Foundation                0x21f3f4f7 _NSLogv + 126
8  Foundation                0x21e8679d NSLog + 28
9  UIKit                     0x259b45fb -[UITableView reloadData] + 1818
10 Simple Meeting Minutes    0x91fff -[MMDetailTableVC saveItemEntry:] (MMDetailTableVC.m:1407)
11 Simple Meeting Minutes    0xa2edf -[MMItemViewController saveButtonAction:] (MMItemViewController.m:526)
12 UIKit                     0x25905771 -[UIApplication sendAction:to:from:forEvent:] + 80
13 UIKit                     0x25a86c71 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 140
14 UIKit                     0x25905771 -[UIApplication sendAction:to:from:forEvent:] + 80
15 UIKit                     0x25905701 -[UIControl sendAction:to:forEvent:] + 64
16 UIKit                     0x258ed61f -[UIControl _sendActionsForEvents:withEvent:] + 446
17 UIKit                     0x258ed74b -[UIControl _sendActionsForEvents:withEvent:] + 746
18 UIKit                     0x25905051 -[UIControl touchesEnded:withEvent:] + 616
19 UIKit                     0x25904cbf -[UIWindow _sendTouchesForEvent:] + 646
20 UIKit                     0x258fd5d7 -[UIWindow sendEvent:] + 642
21 UIKit                     0x258ce119 -[UIApplication sendEvent:] + 204
22 UIKit                     0x258cc757 _UIApplicationHandleEventQueue + 5134
23 CoreFoundation            0x216f9257 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
24 CoreFoundation            0x216f8e47 __CFRunLoopDoSources0 + 454
25 CoreFoundation            0x216f71af __CFRunLoopRun + 806
26 CoreFoundation            0x21649bb9 CFRunLoopRunSpecific + 516
27 CoreFoundation            0x216499ad CFRunLoopRunInMode + 108
28 GraphicsServices          0x228c3af9 GSEventRunModal + 160
29 UIKit                     0x25935fb5 UIApplicationMain + 144
30 Simple Meeting Minutes    0x8c59f main (main.m:16)
31 libdispatch.dylib         0x212fc873 (Missing)
这是我为
saveItemEntry
编写的代码,它似乎总是发生崩溃的地方

- (void)saveItemEntry:(MMitem *)item{

    if (item)
    {
         NSString *resultStr = [self.meetingModel saveItem:item];

        if ([resultStr isEqualToString:@"OK"])
        {
            // all good so close form and refresh data
            [_itemViewController dismissViewControllerAnimated:NO completion:nil];

            [self.tableView reloadData];

            // or if there is an error result then display message
        }
        else if ([resultStr isEqualToString:@"DescriptionNotesMissing"])
        {
            [self showAlert:@"Missing Description or Notes" :@"An Item Description or Notes is required" :0];
            [self.itemViewController.itemDescription becomeFirstResponder];
        }
        // for any other error do nothing
    }
}

我们不知道您是否在主线程中调用此方法

而且tableview在重新加载其单元格时也需要时间。因此,如果您可以在
dispatch\u get\u main\u队列中添加这些代码,那就太好了

dispatch_async(dispatch_get_main_queue(), ^(void){
   [_itemViewController dismissViewControllerAnimated:NO completion:nil];
   [self.tableView reloadData];
}


如果我们正在使用
dispatch\u async(dispatch\u get\u main\u queue(),^(void))从任何通知或委派中刷新UI,这将非常安全{

万岁-终于找到了这个难以捉摸的问题的原因。崩溃是由于在调用
重新加载数据时,用户在表中某个单元格的
UITextfield
内处于编辑模式(由于用户点击其他位置或旋转iPad,这也称为
重新加载数据

我通过在任何
[self.tableView ReloadData]
之前加上
[self.view endEditing:YES]
来解决这个问题,以确保键盘已关闭,单元格未处于编辑模式


确实有道理,但这是一个多么令人讨厌的陷阱。

谢谢Ankit,我从第二个视图控制器MMItemViewController中将该方法称为委托方法。第一个VC是一个包含项目列表的表VC,第二个VC用于编辑项目。用户选择cancel或save调用第一个控件中的appropiate方法。
我还可以我没有注意到我正在使用[\u itemViewController dismissViewControllerAnimated:No completion:nil],在其他地方我使用了[self dismissViewControllerAnimated:No completion:nil]。这两种方法都可以,但我认为第二种方法更正确。你认为这可能相关吗?在使用建议的代码时,它希望看到一个结束括号。我加入如下内容:dispatch_async(dispatch_get_main_queue(),^(void){[\u itemViewController dismissionViewControlleranimated:NO completion:nil];[self.tableView重载数据];})`对吗?你能解释一下你的代码在做什么吗?thanksI只共享了未经测试的代码,可能是括号丢失了。使用dispatch_Async和dispatch_get_main_queue,用户界面在GraphicsService层得到更新,这有助于在多核环境中更新用户界面。如果处理器在某个大型服务器上被阻塞UI在主线程中更新,然后使用GCD with main_queue,我们可以在其他内核中更新其他UI部分。在单核处理器中,GCD使用相同的内核并与主线程序列化。tableview重新加载数据直接在[self.meetingModel saveItem]之后从sqllite3数据库中提取数据方法已将数据保存到数据库中。这一切都发生在主线程上,因此,如果我了解您的情况,在iOS 9下,它可能太忙了,没有为UI提供服务。将dispatch\u Async与dispatch\u get\u main\u队列一起使用可确保在主线程上更新UI。我的回答是否正确?
dispatch_async(dispatch_get_main_queue(), ^(void){
   [self showAlert:@"Missing Description or Notes" :@"An Item Description or Notes is required" :0];
   [self.itemViewController.itemDescription becomeFirstResponder];
}