2011-12-09 39 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

感谢您的答案,但它没有帮助。我觉得这个问题可能是一个线程问题,因为下载是异步执行的,因此在不同的线程上执行。 –