我在uitableviewcell的didselectrow方法上使用它
[NSThread detachNewThreadSelector:@selector(showMyWaitView) toTarget:self withObject:nil];
它工作正常但它在gdb中显示错误,如此
2009-08-10 12:45:01.313 FlashCards [1209:6307] * _NSAutoreleaseNoPool():类UIView的对象0x458200自动释放,没有池到位 - 只是泄漏 堆栈:(0x907d7adf 0x906e41f2 0x29a6 0x906eabad 0x906ea754 0x93e2d6f5 0x93e2d5b2) 2009-08-10 12:45:01.314 FlashCards [1209:6307] * _NSAutoreleaseNoPool():类NSCFString的对象0x2a0e8自动释放,没有池到位 - 只是泄漏 堆栈:(0x907d7adf 0x906e41f2 0x30ad10b0 0x30ad12e6 0x29c5 0x906eabad 0x906ea754 0x93e2d6f5 0x93e2d5b2)
我也试过计时器但是没有用
我的定时器代码是这个
MyTimer = [NSTimer timerWithTimeInterval:0.01 target:self selector:@selector(showMyWaitView)userInfo:nil repeats:NO]; [[NSRunLoop mainRunLoop] addTimer:MyTimer forMode:NSDefaultRunLoopMode];
我也试过这个
MyTimer = [NSTimer scheduledTimerWithTimeInterval:0.0001 target:self selector:@selector(showMyWaitView) userInfo:nil repeats:NO];
[NSThread sleepForTimeInterval:0.03];
这是我的showMyWaitView方法
-(void)showMyWaitView
{
[self.view addSubview:MyWaitViewObj.view];
}
这是我做过的selectrow方法
if(MyWaitViewObj==nil)
{
MyWaitViewObj = [[MyWaitViewController alloc] initWithNibName:@"MyWaitView" bundle:nil];
}
//MyTimer = [NSTimer scheduledTimerWithTimeInterval:0.0001 target:self selector:@selector(showMyWaitView) userInfo:nil repeats:NO];
MyTimer = [NSTimer timerWithTimeInterval:0.01 target:self selector:@selector(showMyWaitView) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:MyTimer forMode: NSDefaultRunLoopMode];
[NSThread detachNewThreadSelector:@selector(showMyWaitView) toTarget:self withObject:nil];
//[NSThread sleepForTimeInterval:0.03];
[indexTableView deselectRowAtIndexPath:indexPath animated:YES];
categoryId = [[listOfCategoryId objectAtIndex:indexPath.section] intValue];
categoryType=[[listOfCategoryType objectAtIndex:indexPath.section] intValue];
[self getFlashCard:categoryId];
flashcardid = [[flashCardsId objectAtIndex:indexPath.row] intValue];
//NSLog(@"%s %d %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__);
if(MyPageViewControllerObj==nil)
{
MyPageViewController *vController= [[MyPageViewController alloc] initWithNibName:@"MyPageView" bundle:[NSBundle mainBundle]];
self.MyPageViewControllerObj=vController;
[vController release];
}
//
MyPageViewControllerObj.sessionid=sessionid;
MyPageViewControllerObj.categoryID = categoryId;
MyPageViewControllerObj.flashcardIdforcount = flashcardid;
MyPageViewControllerObj.categoryType=categoryType;
MyPageViewControllerObj.indexViewControllerobj=self;
[self.navigationController pushViewController:MyPageViewControllerObj animated:YES];
[MyPageViewControllerObj refreshMyPageView];
//[MyPageViewControllerObj release];
NSLog(@"My MySlidingController View Ka retain Count=%d",[MyPageViewControllerObj retainCount]);
[MyWaitViewObj.view removeFromSuperview];
如何使用计时器显示活动指示器请帮助我或告诉我这个gdb错误会导致应用程序崩溃
答案 0 :(得分:1)
如果你正在设置一个Thread,你需要设置run循环并为该线程创建一个NSAutoreleasePool,它在Thread退出时释放。问题是当你像那样关掉你的选择器时你也没有做过。您的showMyWait应该从NSThread documentation
设置发布池非垃圾收集 应用程序,aSelector的方法 负责建立一个 新的自动释放池 分离的线程和释放该池 在它退出之前。垃圾回收 应用程序不需要创建 自动释放池。
答案 1 :(得分:1)
所有UI更新必须在主线程上进行。