2012-04-20 6 views
1

テーブルセルをクリックすると、次のビューをロードする前に1-2秒の短い遅延があります。その間にアクティビティインジケータが表示されているアプリがいくつか見られました。これが私のやりたいことです。私はこのようなものを追加しましたTablecellクリックの短い遅延

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
    spinner.frame = CGRectMake(200,200,200,200); 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.accessoryView = spinner; 
    [spinner startAnimating]; 
    [spinner release]; 

    VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:@"VenueViewController" bundle:[NSBundle mainBundle]]; 

    [self.navigationController pushViewController:vviewcontroller animated:YES]; 
    [vviewcontroller release]; 
    vviewcontroller = nil;} 

しかしこれも遅れて表示され、次のビューが表示される直前です。それは、表のセルをクリックした後1-2秒間アプリがフリーズするように見えるので、アクティビティインジケータは表示されません。

答えて

2

私は、あなたがperformSelectorメソッドを使ってloadメソッドを呼び出すべきだと思っています。別のヒントは、この操作を時間を消費しないように、アクティビティを隠したり表示したりすることです。

だからこれはあなたのViewControllerクラス定義内その

の擬似コードのようになります。あなたの実装では

IBOutlet UIActivityIndicatorView *spin; // created in view and hidden 

...

-(void) load{ // your code 
    VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:@"VenueViewController" bundle:[NSBundle mainBundle]]; 

    [self.navigationController pushViewController:vviewcontroller animated:YES]; 
    [vviewcontroller release]; 
    vviewcontroller = nil; 

    spin.hidden=YES; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    spinner.hidden=NO; 

    [self performSelector:@selector(load) withObject:nil afterDelay:0]; 

} 

はそれがお役に立てば幸いです。

+0

なぜperformSelectorを使用しますか? – TompaLompa

+1

次のループサイクルで実行待ちのため、詳細情報:http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.htmlおよびhttp:// developer。 apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject – Williew

+0

ありがとうございます。 performSelectorは何の違いもありませんでしたが、私はiPad 1でテストしています。遅延は新しいiPadではあまり問題にはならないと思います。最後の質問ですが、クリックした表のセルの中でどのようにスピナーを動かすことができますか?今はステージを中心にしています。 – user1104325

関連する問題