0

我在 uitableviewcell 的 didselectrow 方法上使用它

[NSThread detachNewThreadSelector:@selector(showMyWaitView) toTarget:self withObject:nil];

它工作正常,但它在 gdb 中显示这样的错误

2009-08-10 12:45 : 01.313闪存卡[1209:6307] 10 12:45 :01.314抽认卡[1209:6307]

我也试过计时器,但没用

我的定时器代码是这个

MyTimer = [NSTimer timerWithTimeInterval:0.01 target:self 选择器:@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 错误是否会导致应用程序崩溃

4

2 回答 2

1

如果你正在设置一个线程,你需要设置运行循环并为该线程创建一个 NSAutoreleasePool ,当线程退出时释放它。问题是当你像这样触发你的选择器时你什么都没有做。您的 showMyWait 应该设置发布池,来自NSThread 文档

For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. Garbage-collected applications do not need to create an autorelease pool.

于 2009-08-10T07:40:48.910 回答
1

All UI updates must be made on the main thread.

于 2009-08-10T08:47:29.587 回答