gpt4 book ai didi

objective-c - 为什么单击表格单元格时无法添加加载微调器?

转载 作者:行者123 更新时间:2023-12-01 18:30:24 26 4
gpt4 key购买 nike

这是源代码:

- (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。我该如何实现?谢谢。

最佳答案

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
}

关于objective-c - 为什么单击表格单元格时无法添加加载微调器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com