【问题标题】:SHowing Activity Indicator View Using Thread Shows This Error in gdb?使用线程显示活动指示器视图在 gdb 中显示此错误?
【发布时间】:2009-08-10 07:24:28
【问题描述】:

我在 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(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 错误会导致应用程序崩溃

【问题讨论】:

    标签: objective-c iphone gdb nstimer nsthread


    【解决方案1】:

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

    对于非垃圾收集 应用程序,方法 aSelector 是 负责设立一个 新的自动释放池 分离线程并释放该池 在它退出之前。垃圾收集 应用程序不需要创建 自动释放池。

    【讨论】:

    • @Rahul - 为您修改代码不会帮助您学习。您已被告知需要做什么,并且文档中有更多相关信息,该文档已为您提供链接。
    • 感谢先生您的回答有效。让它在自动释放池中工作
    【解决方案2】:

    所有 UI 更新必须在主线程上进行。

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2023-04-07
      • 2016-06-25
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      相关资源
      最近更新 更多