我的单元格中的活动指示器出现此问题。我在这里用这个方法开始动画然后从那里下载数据我重新加载表视图并在numbersResponseData.length != 0
时调用停止动画但是我看不到活动指示器。
我有一个附件视图箭头,当它加载时向左移动我看不到指示器。
这是在tableView:cellForRowAtIndexPath:
方法中:
if(indexPath.section == 0)
{
if ((indexPath.row == 0) && (numbersResponseData.length == 0))
{
cellActivityIndicator =
[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator startAnimating];
[cell setAccessoryView:cellActivityIndicator];
// Call ASIHTTPRequest methods to start xml download/cache process
[self setRequestString:@"Numbers.xml"];
}
//will set other cells up later
}
更新
我在if语句的不同部分添加了UIActivityIndicator调用,现在它将活动指示符应用到每个单元格,但现在我可以看到它们。
if(indexPath.section == 0)
{
cellActivityIndicator =
[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator startAnimating];
[cell setAccessoryView:cellActivityIndicator];
if ((indexPath.row == 0) && (numbersResponseData.length == 0))
{
cellActivityIndicator =
[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator startAnimating];
[cell setAccessoryView:cellActivityIndicator];
// Call ASIHTTPRequest methods to start xml download/cache process
[self setRequestString:@"Numbers.xml"];
}
//will set other cells up later
}
我已经调试了.row if语句并且它被强行调用了..我只是不明白为什么它会从一个if语句而不是下一个语句中起作用。
答案 0 :(得分:1)
我认为您的UIActivityIndicatorView隐藏在UITableView后面。转储此代码并检查您是否能够在视图上看到此指示符
subViewActivityIndicator = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
subViewActivityIndicator.frame=CGRectMake(150, 220, 37, 37);
subViewActivityIndicator.color = [UIColor colorWithRed:0.6 green:1 blue:0 alpha:1.0];
[self.tableview addSubview:subViewActivityIndicator];
[subViewActivityIndicator startAnimating];
删除使用此功能,
[subViewActivityIndicator removeFromSuperview];
答案 1 :(得分:0)
您是从UI循环还是从工作线程调用此代码?如果从工作线程调用,则需要使用performSelectorOnMainThread:来调用UI更改。请参阅:
http://blog.jayway.com/2010/03/30/performing-any-selector-on-the-main-thread/