Ios EXC\u调度\u获取\u主队列()上的错误\u访问
我有这段代码,有时变量dConfiguration为Nil,我得到一个EXC_BAD_访问错误,大多数时候变量表示0个键/值对,错误几乎不可能重现,我只需单击我的按钮,大多数时间工作,但在极少数情况下失败Ios EXC\u调度\u获取\u主队列()上的错误\u访问,ios,objective-c,init,dispatch-async,alloc,Ios,Objective C,Init,Dispatch Async,Alloc,我有这段代码,有时变量dConfiguration为Nil,我得到一个EXC_BAD_访问错误,大多数时候变量表示0个键/值对,错误几乎不可能重现,我只需单击我的按钮,大多数时间工作,但在极少数情况下失败 serviceData = data; dispatch_async(dispatch_get_main_queue(), ^{ [loading removeFromSuperview]; _tvTable.hidden = NO; dConfiguration =[
serviceData = data;
dispatch_async(dispatch_get_main_queue(), ^{
[loading removeFromSuperview];
_tvTable.hidden = NO;
dConfiguration =[NSJSONSerialization JSONObjectWithData:serviceData options:kNilOptions error:nil];
if (![[dConfiguration objectForKey:@"NumberOfLines"] isEqual: [NSNull null]]) {
_NumberOfLines = [[dConfiguration objectForKey:@"NumberOfLines"] integerValue];
} else {
_NumberOfLines = 1;
}
if(badget!=nil){
dBadgets = [NSJSONSerialization JSONObjectWithData:badget options:kNilOptions error:nil];
}
dValue = [dConfiguration objectForKey:sButtonType];
RowCount = (int)dValue.count;
[_tvTable numberOfRowsInSection:RowCount];
[self loadTable];
});
此变量在实现中声明为全局变量:
@implementation vcTableViewEventsManagerEvents {
NSDictionary *dConfiguration;
}
我从未实现过alloc init代码:
dConfiguration = [[NSDictionary alloc] init];
这可能是问题所在吗?如果我总是初始化变量,这个错误不会发生吗?始终进行初始化是一种良好的做法?我在哪里可以看到EXC\u BAD\u访问的更详细信息
谢谢你的帮助
更新1
我尝试将错误视为所有注释,可能我做错了什么,因为错误变量为nil这是屏幕截图:
在这个特定的时间,变量dConfiguration表示0个键/值对,因为我添加了alloc init
我曾尝试过双击,并尽可能快地从选项卡栏项目中进行更改,有时有效,有时无效
更新2
正如您所问,这是错误的原因:
线程#1:tid=0x7bfdfd,0x2537dd52基础newJSONString+98,
队列='com.apple.main thread',停止原因=EXC\u错误访问(代码=1,
地址=0x3fe64a2)
帧#0:0x2537dd52基础
newJSONString+98
框架#1:0x2537d300基础newJSONValue+1976
帧#2:0x2537cf04基础
newJSONValue+956
帧#3:0x2537d380基础newJSONValue+2104
框架#4:0x2537ca80基础
-[\u NSJSONReader parseUTF8JSONData:skipBytes:options:+176
帧#5:0x2537c88e基础-[[u NSJSONReader parseData:options:][238]
帧#6:0x2537c718基础
+[NSJSONSerialization JSONObjectWithData:options:error:+156
框架#7:0x00121b24访客体验\uuu 43-[vcTableViewEvents管理预览
检查JSON]\u块调用\u 2(.block\u描述符=0x17040f40)+244 at
vcTableViewEventsManagerEvents.m:298
帧#8:0x00495b7e libdispatch.dylib
_dispatch_call_block_和_release+10
第9帧:0x00495b6a libdispatch.dylib\u dispatch\u client\u callout+22
帧#10:0x0049a654 libdispatch.dylib
_dispatch_main_queue_callback_4CF+1680
帧#11:0x24b81bdc CoreFoundation\uuu CFRUNLOOP\u正在为\u主\u调度\u队列\uu8提供服务
帧#12:0x24b800d6 CoreFoundation
\uu CFRunLoopRun+1574
帧#13:0x24acf2e8 CoreFoundationCFRunLoopRunSpecific+520
帧#14:0x24acf0d4 CoreFoundation
CFRunLoopRunInMode+108
帧#15:0x260bfac8图形服务GSEventRunModal+160
帧#16:0x291940b8 UIKit
UIApplicationMain+144
帧#17:0x001cb6f0访客体验main(argc=1,argv=0x00473b5c)+106位于main处。m:16
帧#18:0x24777872 libdyld.dylib
start+2
更新3
我在控制台中执行了此命令以查看JSON,在我看来是正确的:
(lldb) po (NSString *)[[NSString alloc] initWithData:serviceData encoding:4]
{
"BackgroundImage": null,
"ButtonGallery": null,
"Buttons": null,
"ButtonsEvents": [{
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "04 JUN 2016 - Horario: 11.00 - 18.00",
"Id": 23,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_15f37703-f0a0-4f10-be70-76e0118fa9f9_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_15f37703-f0a0-4f10-be70-76e0118fa9f9_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "134",
"ItemType": null,
"JsonConfigFile": "134es",
"Label": "Brazil Pool Party",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Brazil Pool Party",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "23 JUN 2016 - Horario: 20:00 - 01:00",
"Id": 29,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_5af125bb-1bdf-4fcf-9306-3b565cdbb928_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_5af125bb-1bdf-4fcf-9306-3b565cdbb928_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "140",
"ItemType": null,
"JsonConfigFile": "140es",
"Label": "Noche de San Juan",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche de San Juan",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "02 JUL 2016 - Horario: 21:00 - 1:00",
"Id": 30,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_7227de52-8d27-4a65-bdf7-dea08e37b968_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_7227de52-8d27-4a65-bdf7-dea08e37b968_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "141",
"ItemType": null,
"JsonConfigFile": "141es",
"Label": "Noche Amàre",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche Amàre",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "09 JUL 2016 - Horario: 22:00 - 00:00",
"Id": 28,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_4ad05ca3-c345-4a6f-aeb9-972610056b86_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_4ad05ca3-c345-4a6f-aeb9-972610056b86_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "139",
"ItemType": null,
"JsonConfigFile": "139es",
"Label": "Noche Flamenca Beach",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche Flamenca Beach",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "20 JUL 2016 - Horario: 19:00 - 22:00",
"Id": 27,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_161bab39-5ac6-43a0-84c4-5c0fa764b5b0_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_161bab39-5ac6-43a0-84c4-5c0fa764b5b0_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "138",
"ItemType": null,
"JsonConfigFile": "138es",
"Label": "Noche de luna llena",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche de luna llena",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "23 JUL 2016 - Horario: 21:00 - 00:00",
"Id": 26,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_c657d56d-5f24-4f28-8d0c-66afb2fae1ad_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_c657d56d-5f24-4f28-8d0c-66afb2fae1ad_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "137",
"ItemType": null,
"JsonConfigFile": "137es",
"Label": "Noche cubana",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche cubana",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "06 AGO 2016 - Horario: 22:00 - 00:00",
"Id": 31,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_98032ab6-b689-42d6-b19b-6b82705478a3_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_98032ab6-b689-42d6-b19b-6b82705478a3_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "142",
"ItemType": null,
"JsonConfigFile": "142es",
"Label": "Noche Flamenca Beach",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche Flamenca Beach",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "13 AGO 2016 - Horario: 21:00 - 00:00",
"Id": 32,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_447f28d9-ed38-4482-868e-74743cbb5a89_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_447f28d9-ed38-4482-868e-74743cbb5a89_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "143",
"ItemType": null,
"JsonConfigFile": "143es",
"Label": "Noche cubana",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Noche cubana",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "10 SEP 2016 - Horario: 11:00 - 18:00",
"Id": 33,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_a7328a94-d64d-4fd4-b0a1-a2c126c8c92c_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_a7328a94-d64d-4fd4-b0a1-a2c126c8c92c_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "144",
"ItemType": null,
"JsonConfigFile": "144es",
"Label": "Pool Party",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Pool Party",
"ViewController": 21
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "17 SEP 2016 - Horario: 12:00 - 18:00",
"Id": 25,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_9f8af8e5-56d7-433f-9661-9403196faad8_x320.jpg",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_9f8af8e5-56d7-433f-9661-9403196faad8_x320.jpg",
"ImageRetinaHeighlighted": null,
"Item": "136",
"ItemType": null,
"JsonConfigFile": "136es",
"Label": "Oktoberfest",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Oktoberfest",
"ViewController": 21
}],
"ButtonsPromotions": [{
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 18,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_ba95942c-1ece-4332-9f95-eb3f95738f41_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_ba95942c-1ece-4332-9f95-eb3f95738f41_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "126",
"ItemType": null,
"JsonConfigFile": "126es",
"Label": "Desayuna con Nosotros",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Desayuna con Nosotros",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 19,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_3b9f1e44-5f33-4eb9-987b-5e50dcaed2a7_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_3b9f1e44-5f33-4eb9-987b-5e50dcaed2a7_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "127",
"ItemType": null,
"JsonConfigFile": "127es",
"Label": "Disfruta de Nuestra Cena Buffet",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Disfruta de Nuestra Cena Buffet",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 20,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_f0ec90c9-3383-48f7-b5cf-28a236aee9e9_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_f0ec90c9-3383-48f7-b5cf-28a236aee9e9_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "128",
"ItemType": null,
"JsonConfigFile": "128es",
"Label": "Alquiler de Bicicletas Vintage",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Alquiler de Bicicletas Vintage",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 21,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_f72a03bf-ddd2-486e-a289-cb3e82bd08db_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_f72a03bf-ddd2-486e-a289-cb3e82bd08db_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "129",
"ItemType": null,
"JsonConfigFile": "129es",
"Label": "Parking",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Parking",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 22,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_3dd87e35-2ae3-4ef2-a70a-f1b44e41d27a_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_3dd87e35-2ae3-4ef2-a70a-f1b44e41d27a_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "130",
"ItemType": null,
"JsonConfigFile": "130es",
"Label": "Ofertas de Grab & Go",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Ofertas de Grab & Go",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 13,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_b8187a48-1b03-4b29-a403-f03af8433c4f_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_b8187a48-1b03-4b29-a403-f03af8433c4f_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "92",
"ItemType": null,
"JsonConfigFile": "92es",
"Label": "Habitación \"The One\"",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Habitación \"The One\"",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 14,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_fc20ec9b-2107-4828-9796-d5234dbe80fd_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_fc20ec9b-2107-4828-9796-d5234dbe80fd_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "98",
"ItemType": null,
"JsonConfigFile": "98es",
"Label": "Disfruta de una Salida de Habitación más Tarde",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Disfruta de una Salida de Habitación más Tarde",
"ViewController": 20
}, {
"BadgeCount": 0,
"ClientId": 0,
"Frequency": "",
"Id": 15,
"Image": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_be514668-27d0-4ee8-995e-0f8f89936c9b_x320.png",
"ImageHeighlighted": null,
"ImageIconTitle": "",
"ImageRetina": "http:\/\/ServerCloud.CloudApp.net\/DesktopServerCloud\/ClientData\/4\/Images\/GVT_be514668-27d0-4ee8-995e-0f8f89936c9b_x320.png",
"ImageRetinaHeighlighted": null,
"Item": "103",
"ItemType": null,
"JsonConfigFile": "103es",
"Label": "Habitación categoría superior",
"LongTitle": null,
"Selector": "btnAction:",
"SubLabel": null,
"Title": "Habitación categoría superior",
"ViewController": 20
}],
"ButtonsTabList": null,
"DatePeriod": null,
"Details": null,
"Disclaimer": null,
"MessageList": null,
"NoBooking": null,
"NumberOfLines": 2,
"Pins": null,
"Selector": null,
"ServiceType": null,
"TabList": null,
"Texts": null,
"Titles": null,
"Url": null,
"UserCode": null
}
修改块内的变量时,必须使用
\u块
说明符
__block NSDictionary *dConfiguration;
__block NSData *serviceData = data;
dispatch_async(dispatch_get_main_queue(), ^{
//...
});
您不需要alloc/init,因为您需要[NSJSONSerialization stuff]并为其分配返回值。但是当它发生时,
serviceData
nil?另外,能否在JSONObjectWithData:options:error:
中添加NSError
参数?如果您在按钮上快速单击两次,是否会发生错误?请尝试在旁边的直线处传递错误变量:任何向SO发布有关崩溃或错误的消息,并且有一个方法调用,其中nil
被传递到NSError**
参数,则应立即删除其SO发布权限。这是调试的绝对基本级别。(事实上,这对这次崩溃没有帮助,但是,在达到这一点之前,应该付出更多的努力。)@Larme serviceData不是零,它有正确的JSON数据,当我快速更改选项卡中的部分时,会发生错误,我将尝试传递错误变量并发布results@AvinashSharma我将尝试传递错误变量并发布结果我可以在全局变量中使用_块说明符吗?或者我应该制作一个副本并使用它吗?谢谢你的帮助,但是_块说明符不起作用。最后,我简化了代码,但是直到,它更难复制,但它仍然在发生,因此,我添加了_块说明符,从昨天起,我无法再现错误,因此我将把这个答案设置为正确答案。嗨@Marcantoniouzcateguipescoz,很抱歉答案延迟。我很高兴我的回答让你找到了解决办法。祝你有美好的一天