2011-12-09 10 views
0

私はこれ以上少し私の髪を引っ張ってきました。私は非常に単純なアプリケーションを作成しています、それは単にRSSフィードをダウンロードし、それをUINavigationControllerの中にあるUITableviewに表示します。それは私がモーダルビューを提示しているフィードをダウンロードしている間。DismissModalViewが動作しません

私のモーダルビューでは、私はUIImageViewとスピンするように設定されているUIActivityIndi​​catorViewを表示しています。私はASIHTTRequestを使用してフィードを非同期的に取得し、次に補完ブロックを使用して応答文字列を取得し、スピナーまたは失敗ブロックを停止してNSErrorを取得し、アラートビューを表示します。これはすべて完全に機能します。

私は、コンプリーションブロック内で呼び出されるテーブルビューからモーダルビューを閉じるプロトコルを作成しました。しかしモーダルビューは決して解雇されません!私はナビゲーションコントローラにプッシュしようとしましたが、まったく同じ問題が発生します。私は、モーダルビューのデリゲートをnilに設定しようとしましたが、まだ運がありません。

私はASIHTTPRequestデリゲートメソッドを使用してブロックなしでチェックしました。これは同じです。モーダルビューを表示しないと、テーブルビューは正常に表示されます。

すべてのアイデア?私はdeallocと未使用の関数だけでなく、すべてのtableviewデリゲートとデータソースメソッドをスキップしました。 ModalViewのための私の理解で

@interface MainTableViewController() 
-(void)loadModalView; 
@end 


@implementation MainTableViewController 
@synthesize tableView; 
@synthesize modalView; 

// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView 
{ 

    [super loadView]; 
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStylePlain]; 
tableView.delegate = self; 
tableView.dataSource = self; 
[self.view addSubview:tableView]; 

    [self loadModalView]; 


} 

-(void)loadModalView 
{ 
    modalView = [[ModalViewController alloc]init]; 
    modalView.delegate = self; 
    [self presentModalViewController:modalView animated:NO]; 

} 


//Modal View Delegate 
-(void)downloadComplete 
{ 
modalView.delegate = nil; 
[self dismissModalViewControllerAnimated:NO]; 



} 


@end 


@interface ModalViewController() 


- (void)loadView 
{ 
[super loadView]; 

backgroundImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; 

[self.view addSubview:backgroundImage]; 

spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
spinner.frame = CGRectMake(160, 240, spinner.bounds.size.width, spinner.bounds.size.height); 
spinner.hidesWhenStopped = YES; 
[self.view addSubview:spinner]; 
[spinner startAnimating]; 


NSString* urlString = FEED_URL; 
NSURL* url = [NSURL URLWithString:urlString]; 

ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; 
[request setCompletionBlock:^{ 
    // Use when fetching text data 
    NSString *responseString = [request responseString]; 
    [spinner stopAnimating]; 
    [delegate downloadComplete]; 
    // Use when fetching binary data 

}]; 
[request setFailedBlock:^{ 
    NSError *error = [request error]; 
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Error" message:error.description delegate:self cancelButtonTitle:@"Continute" otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
}]; 
[request startAsynchronous]; 



} 

マット

答えて

0

私はこれを解決する唯一の方法もののエラーは同期的にデータをダウンロードし、ダウンロードビューをナビゲーションスタックにプッシュ&ポップすることでした。理想的ではないが動作する。

0

..あなたソリューションは非常に複雑である。..クラスMainTableViewControllerは、フィードをダウンロード ものであれば が、それは良いことではないでしょう...それがされますちょうどので、あなたのMainTableViewControllerのloadViewメソッド内 .. ActivityIndi​​catorとして機能し、ダウンロードした後に解任:

- (void)loadView 
{ 
    NSString* urlString = FEED_URL; 
    NSURL* url = [NSURL URLWithString:urlString]; 

    ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; 
    [request startAsynchronous]; 
    //after starting the request show immediately the modalview 
    modalView = [[ModalViewController alloc]init]; 
    [self presentModalViewController:modalView animated:NO]; 

    [request setCompletionBlock:^{ 
    // Use when fetching text data 
    NSString *responseString = [request responseString]; 
    //then when it is complete dissmiss the modal 
    [modalView dismissModalViewControllerAnimated:NO]; 

    // Use when fetching binary data 
    }]; 
    [request setFailedBlock:^{ 
    NSError *error = [request error]; 
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Error" message:error.description delegate:self cancelButtonTitle:@"Continute" otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
    }]; 


} 

を私は私のプロジェクトで使用するブロックをdidntの、しかし、私は思いますそれは同じように動作します。.. も私はサブビューとして(大)無地UIActivityIndi​​catorViewを使用しないでmodalViews ...悲しいことに私は今ここにコードをテストカント..しかし、私は後でそれを確認することができます

+0

回答ありがとうございましたが、役に立たなかったです。ダウンロードが非同期的に、したがって別のスレッドで実行されるため、問題がスレッドの問題である可能性があります。 –

関連する問題