集成到搜索栏中的活动指示器不会显示在iPhone SDK中

Par*_*att 6 iphone cocoa-touch objective-c uiactivityindicatorview ios4

在我的iPhone应用程序中,我想在搜索栏上添加活动指示器.

在搜索时,它应显示活动指示器.

我在XIB中添加了活动指示器并创建了它的插座.

我在搜索结束时隐藏它.

但不显示活动指示器.

问题

我发现搜索功能(比如A)(我为活动指示器设置动画)依次调用另一个函数(比如B),因此主线程用于执行函数B.但是对于动画的活动指示器我们需要主线.

所以我尝试使用performSelectorInBackGround:withObject方法调用函数B. 现在,当我单击搜索时,会显示活动指示器,但功能B的功能不会执行.

有什么可以解决这个问题?

请帮助和建议

谢谢

Par*_*att 0

我已经得到了解决方案,如下所示。

我刚刚在“搜索”按钮单击事件中编写了以下行。

[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];

并定义函数threadStartAnimating:如下:

-(void)threadStartAnimating:(id)data
{
   [activityIndicator setHidden:NO];
   [activityIndicator startAnimating]; 
}
Run Code Online (Sandbox Code Playgroud)