使用线程显示活动指示器视图在 gdb 中显示此错误?

发布于 2024-08-01 20:31:18 字数 3195 浏览 5 评论 0原文

我在 uitableviewcell 的 didselectrow 方法上使用它,

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

它工作正常,但它在 gdb 中显示错误,如下所示

2009-08-10 12:45:01.313 FlashCards[1209:6307] * _NSAutoreleaseNoPool(): Object 0x458200 of class UIView autoreleased with no泳池就位 - 只是漏水 堆栈:(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 目标:self 选择器:@selector(showMyWaitView) userInfo:nil 重复:不]; [[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];
}

这是我的 did 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 错误会导致应用程序崩溃

i m using this on uitableviewcell's didselectrow method

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

it works fine but it shows error in gdb like this

2009-08-10 12:45:01.313 FlashCards[1209:6307] * _NSAutoreleaseNoPool(): Object 0x458200 of class UIView autoreleased with no pool in place - just leaking
Stack: (0x907d7adf 0x906e41f2 0x29a6 0x906eabad 0x906ea754 0x93e2d6f5 0x93e2d5b2)
2009-08-10 12:45:01.314 FlashCards[1209:6307] *
_NSAutoreleaseNoPool(): Object 0x2a0e8 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x907d7adf 0x906e41f2 0x30ad10b0 0x30ad12e6 0x29c5 0x906eabad 0x906ea754 0x93e2d6f5 0x93e2d5b2)

i have also tried timer but that didn't work

my Timer Code is This

MyTimer = [NSTimer timerWithTimeInterval:0.01 target:self selector:@selector(showMyWaitView) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:MyTimer forMode: NSDefaultRunLoopMode];

i have also tried this

MyTimer = [NSTimer scheduledTimerWithTimeInterval:0.0001 target:self selector:@selector(showMyWaitView) userInfo:nil repeats:NO]; 

[NSThread sleepForTimeInterval:0.03];

and this is my showMyWaitView method

-(void)showMyWaitView
{
[self.view addSubview:MyWaitViewObj.view];
}

here is my did selectrow method

  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];

how do i show activity indicator using timer please help me or tell me will this gdb error cause application crash

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南…巷孤猫 2024-08-08 20:31:18

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

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

If you're setting up a Thread, you need to set up the run loop and create an NSAutoreleasePool for that thread as well, which is released when the Thread exits. The problem is you're doing neither when you fire off your selector like that. Your showMyWait should set up the release pool, from NSThread documentation

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.

孤蝉 2024-08-08 20:31:18

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

All UI updates must be made on the main thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文