以下是源代码:
- (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
}
loadingWithBackground的代码:
-(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,但它也无法显示。当我在loadingWithBackground
中复制方法:didSelectRowAtIndexPath
时,它也不会显示loadingWithBackground
。我怎样才能实现它?谢谢。
答案 0 :(得分:4)
NSInteger SelectedIndex;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SelectedIndex = indexPath.row;
// Start animating activity indicator
[self performSelectorOnMainThread:@selector(performIndexPath) withObject:nil waitUntilDone:NO];
// OR USING TIMER
// timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(performIndexPath) userInfo:nil repeats:NO];
}
-(void)performIndexPath {
//stop activity indicator
}
答案 1 :(得分:0)
我会尝试一些事情:
将[m_oUIActivityIndicatorView startAnimating];
移至performLoadingWithBackground
方法的末尾,然后调用该方法而不是loadingWithBackground
。似乎差不多。
在[self.view bringSubviewToFront:m_oUIActivityIndicatorBackgroundView];
之后添加[self.view addSubview:m_oUIActivityIndicatorBackgroundView];
。不确定它是否会有所帮助,但我总是这样做
调试
希望有所帮助