내 iPhone 앱에서 CMS 기능을 원한다. 인터넷에서 텍스트와 이미지를로드하고 UIImageView, UIButton 및 UITextView에 적용하려고합니다. 그러나 나는 오류가 발생합니다. 현재 코드는 이미지 로딩과 잘 작동합니다. viewDidAppear 코드에 텍스트 코드가 있지만 사용자가 텍스트가로드 될 때까지 화면과 상호 작용할 수 없어서 이미지가있는 loadInfo 메서드로 이동되었지만이 방법이 좋지 않았고 나쁜 액세스가 발생했습니다. 오류. 콘솔에 다음 내용을 인쇄했습니다.백그라운드에서 UIButton 및 UITextView의 텍스트로드 (간단한 CMS)
2011-05-08 21:26:13.770 Fraction Calculator Lite[2184:6b03] bool _WebTryThreadLock(bool), 0x62338d0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
누구든지 내 문제가 될 수 있습니다.
감사합니다.
이- (void)viewDidAppear:(BOOL)animated {
[self performSelectorInBackground:@selector(loadInfo) withObject:nil];
}
-(void) loadInfo {
NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
NSError *error;
NSString *internetTest = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://lindahlstudios.com/cms/internettest.txt"] encoding:NSUTF8StringEncoding error:&error];
if ([internetTest isEqualToString: @"Internet Connection Complete"]) {
UIImage *img1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://lindahlstudios.com/cms/adimage.png"]]];
[image1 setImage:img1];
[img1 release];
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://lindahlstudios.com/cms/adtext.txt"] encoding:NSUTF8StringEncoding error:&error];
NSString *string2 = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://lindahlstudios.com/cms/price.txt"] encoding:NSUTF8StringEncoding error:&error];
[adText setText:string]; //Thread 8: Program received signal: "EXC_BAD_ACCESS"
[price setTitle:string2 forState:UIControlStateNormal];
}
[arPool release];
}