我一直在拉我的頭髮。我創建了一個非常簡單的應用程序,它只需下載一個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];
}
馬特
感謝您的答案,但它沒有幫助。我覺得這個問題可能是一個線程問題,因爲下載是異步執行的,因此在不同的線程上執行。 –