2011-12-09 78 views
0

我一直在拉我的頭髮。我創建了一個非常簡單的應用程序,它只需下載一個rss提要並將其顯示在UINavigationController中的UITableview中。在下載Feed時,我正在展示一個模態視圖。DismissModalView不能正常工作

在我的模態視圖中,我顯示了一個UIImageView和一個設置爲旋轉的UIActivityIndi​​catorView。我使用ASIHTTRequest異步抓取feed,然後使用完成塊獲取響應字符串並停止微調框或失敗塊以獲取NSError並顯示警報視圖。這一切都完美。

我已經創建了一個協議,用於在完成塊內調用tableview中的模式視圖。但模態的觀點是永遠不會被駁回的!我嘗試將其推入導航控制器,但發生了完全相同的問題。我甚至嘗試將模態視圖委託設置爲零,但仍然沒有運氣。

我已經使用ASIHTTPRequest委託方法檢查了它沒有塊,並且它是相同的,如果我不提供模式視圖,表視圖顯示正常。

任何想法?我已經跳過了所有的tableview委託和數據源方法以及dealloc和任何未使用的函數。

@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是 一個誰下載飼料。對於ModalView它會只是作爲一個ActivityIndi​​cator和下載後解僱.. 所以你MainTableViewController的loadView內:

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


} 

我沒有使用的塊在我的項目,但我認爲它會工作相同.. 也我使用普通UIActivityIndi​​catorView(大)作爲子視圖不modalViews ..可悲的是我現在不能測試代碼..但我可以稍後檢查它

+0

感謝您的答案,但它沒有幫助。我覺得這個問題可能是一個線程問題,因爲下載是異步執行的,因此在不同的線程上執行。 –