rui*_*ano 0 cocoa-touch exc-bad-access objective-c autorelease
我有一个简单的UIViewControler,当我调用方法[self performSelectorInBackground:@selector(load)withObject:nil]; 它导致和EXC_BAD_ACCESS
这是UIViewControler.m和UIViewControler.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) UITextView *myTextView;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize myTextView;
- (id)init {
self = [super init];
if (self) {
myTextView = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[self view] addSubview:myTextView];
[self performSelectorInBackground:@selector(load) withObject:nil];
}
return self;
}
- (void) load {
@autoreleasepool {
[myTextView setText:@"LOADING ..."];
//DO SOMETHING ....
}
}
@end
Run Code Online (Sandbox Code Playgroud)
PS:
该项目使用Objective-C ARC
UIKit对象不是线程安全的:您只能在主线程上访问它们.该行[myTextView setText:@"LOADING ..."];
无法在后台线程中安全执行.
这可能是也可能不是你得到EXC_BAD_ACCESS
错误的原因但没有看到load
方法的其余部分我无法知道还有什么可能是错的.
归档时间: |
|
查看次数: |
1092 次 |
最近记录: |