我一直在拉我的头发。我创建了一个非常简单的应用程序,它只需下载一个rss提要并将其显示在UINavigationController中的UITableview中。在下载Feed时,我正在展示一个模态视图。DismissModalView不能正常工作
在我的模态视图中,我显示了一个UIImageView和一个设置为旋转的UIActivityIndicatorView。我使用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];
}
马特
感谢您的答案,但它没有帮助。我觉得这个问题可能是一个线程问题,因为下载是异步执行的,因此在不同的线程上执行。 –