error when add uitableviewcontroller as subview in uiviewcontroller

假如想象 提交于 2019-12-03 20:39:57

thanks for the help

I finally figure it out I used

[self addChildViewController:subController];
[mainView addSubview:subController.view];

to add the tableview to the viewcontroller as subview

and it worked

latestArray has not be initialized correctly.

Any time you get EXEC_BAD_ACCESS, run your code through the Zombies Instrument. This will point to any problematic code.

The objects latestsImg1 and latestsLogo1 are not being retained when they are initialized. Therefore, when the async code block executed within the dispatch_async is run those values are probably already released and no longer valid. So, when the async block executes those two pointers are point off into oblivion. I suggest either not doing those two assignments via GrandCentral dispatch, or if you must do them asynchronously, then retain them after creation and release them within the async block.

Something like:

NSData *latestsImg1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:img1]]; [latestsImg1 retain]; NSData *latestsLogo1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:logo1]];
[latestsLogo1 retain]; cell.latest_name_en1.text = latest_name_En;

dispatch_async(dispatch_get_main_queue(), ^{

    cell.latest_img1.image = [UIImage imageWithData:latestsImg1];

cell.latest_logo1.image = [UIImage imageWithData:latestsLogo1];
[latestsImg1 release];
    [latestLogo1 release];

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!