0

uitableviewcellのdidselectrowメソッドでこれを使用しています

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

正常に動作しますが、このようにgdbにエラーが表示されます

2009-08-10 12:45:01.313 Flashcards [1209:6307] * _nsautorleaseNopool():オブジェクト0x458200クラスUiviewオートリリースはプールを所定の位置に漏らしていない - (0x907d7adf 0x906e41f2 0x29a6022222020222222029a6022222029a6 10 12:45:01.314フラッシュカード[1209:6307] * _NSAUTORLEASENOPOOL():クラスNSCFストリングのオブジェクト0x2A0E8オートリリースされているプールがあります。

タイマーも試しましたがダメでした

私のタイマーコードはこれです

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

タイマーを使用してアクティビティ インジケーターを表示する方法

4

2 に答える 2

1

すべてのUIの更新は、メインスレッドで行う必要があります。

于 2009-08-10T08:47:29.587 に答える
1

スレッドを設定している場合は、実行ループを設定し、そのスレッドの NSAutoreleasePool も作成する必要があります。これは、スレッドが終了したときに解放されます。問題は、そのようにセレクターを起動するときにどちらも実行していないことです。showMyWait は、 NSThread のドキュメントから、リリース プールを設定する必要があります。

ガベージ コレクションされていないアプリケーションの場合、メソッド aSelector は、新しく切り離されたスレッドの自動解放プールを設定し、終了する前にそのプールを解放します。ガベージ コレクションされたアプリケーションは、自動解放プールを作成する必要はありません。

于 2009-08-10T07:40:48.910 に答える