Вот исходный код:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self loadingWithBackground]; //this view called the spinner
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSelectorOnMainThread:@selector(performIndexPath:)
withObject:indexPath
waitUntilDone:YES];
}
-(void)performIndexPath:(NSIndexPath *)aIndexPath{
//application logic, flip the view over, and display the data
}
Но это работает совершенно правильно:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self loadingWithBackground];
return;
//bababbaa
}
код загрузки с фоном:
-(void)loadingWithBackground{
[self performSelectorOnMainThread:@selector(performLoadingWithBackground)
withObject:NULL
waitUntilDone:YES];
[m_oUIActivityIndicatorView startAnimating];
}
-(void)performLoadingWithBackground{
self.m_isLoadFinished = NO;
if(m_oUIActivityIndicatorView != NULL){
[m_oUIActivityIndicatorView removeFromSuperview];
m_oUIActivityIndicatorView = NULL;
}
if(m_oUIActivityIndicatorBackgroundView != NULL){
[m_oUIActivityIndicatorBackgroundView removeFromSuperview];
m_oUIActivityIndicatorBackgroundView = NULL;
}
m_oUIActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[m_oUIActivityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
m_oUIActivityIndicatorBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m_oUIActivityIndicatorView.frame.size.width, m_oUIActivityIndicatorView.frame.size.height)];
[m_oUIActivityIndicatorBackgroundView setBackgroundColor:[UIColor grayColor]]; //I love the black one
[m_oUIActivityIndicatorBackgroundView setAlpha:0.8];
[m_oUIActivityIndicatorBackgroundView setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0)];
m_oUIActivityIndicatorBackgroundView.layer.cornerRadius = 10;
[m_oUIActivityIndicatorBackgroundView addSubview:m_oUIActivityIndicatorView];
m_oUIActivityIndicatorView.hidden = NO;
[self.view addSubview:m_oUIActivityIndicatorBackgroundView];
}
Я попытался выполнить загрузку с помощью основного потока, но он также не может отображаться. Когда я копирую метод: loadingWithBackground
в didSelectRowAtIndexPath
, он не показывает ни loadingWithBackground
. Как мне этого добиться? Благодарю.