V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
INT21H
V2EX  ›  iDev

TableView 中 reloadData 时 EXC_BAD_ACCESS 的问题

  •  
  •   INT21H · 2014-05-03 16:15:49 +08:00 · 3930 次点击
    这是一个创建于 3636 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在使用 AFNetworking 库(1.x),然后在异步刷新时候,在

    [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
    ...

    [self.jsonData addObjectsFromArray:JSON[@"objects"]];

    dispatch_async(dispatch_get_main_queue(), ^{
    [self.titleLabel setFrame:CGRectMake(60, 5, 100, 40)];
    [self.tableView reloadData];
    });

    ...
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
    ...
    }];

    上面主要是在获得数据后,在主线程更新 UI(reloadData)。然后发现*有时候*,会出现 EXC_BAD_ACCESS,查看 crash report 显示是 [self.titleLabel setFrame:CGRectMake(60, 5, 100, 40)]; 这一行。

    请问这样写是有什么问题么?
    5 条回复    2014-05-13 09:16:30 +08:00
    dorentus
        1
    dorentus  
       2014-05-03 16:55:01 +08:00 via iPhone   ❤️ 1
    non-ARC?

    self.titleLabel 是什么,可能是它的问题吧
    INT21H
        2
    INT21H  
    OP
       2014-05-03 18:00:27 +08:00
    @dorentus ARC

    self.titleLabel 是自定义的一个 label,但是 setFrame 在主线程中操作也不会有问题吧?
    alexrezit
        3
    alexrezit  
       2014-05-03 18:18:32 +08:00 via iPhone   ❤️ 1
    __weak
    cielpy
        4
    cielpy  
       2014-05-03 18:37:44 +08:00   ❤️ 1
    没记错的话[@"objects"]这咱写法是6.0才有的吧,那为什么不用AF 2.x版本呢。
    block回调有对象的循环引用问题,这个我现在也没太搞明白,LS提到__weak应该是指这个问题吧
    看看那个label setFrame的时候还在不在,然后数组有没有越界?
    R0CKSTAR
        5
    R0CKSTAR  
       2014-05-13 09:16:30 +08:00
    Diagnostics里面把Enable Zombie Objects打开,看log就能知道是哪个对象野了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1032 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:58 · PVG 03:58 · LAX 12:58 · JFK 15:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.