我目前推動另一個視圖控制器之前開始活動的指標動畫但它不啓動動畫的活動的指標。活動指示燈不啓動時的視圖控制器是導航到另一個視圖控制器
[activityindicator startanimating];
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[activityindicator stopanimating];
我目前推動另一個視圖控制器之前開始活動的指標動畫但它不啓動動畫的活動的指標。活動指示燈不啓動時的視圖控制器是導航到另一個視圖控制器
[activityindicator startanimating];
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[activityindicator stopanimating];
創建一個NSThread呼叫選擇如下:
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
// Some code
[spinner stopAnimating];
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
threadStartAnimating:
-(void)threadStartAnimating:(id)data
{
[spinner startAnimating];
}
謝謝你這麼多 – 2011-05-12 10:40:18
很高興它幫助:) – Nitish 2011-05-12 10:49:46
這樣做(當然,有dispatch_async和默認優先級隊列)爲我工作,但我不知道這是爲什麼。 Nitish,你知道爲什麼你的解決方案有效嗎? – livings124 2013-11-15 00:54:00
試試這個代碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
[self performSelector:@selector(navigatetodeals) withObject:nil afterDelay:.5];
}
-(void)navigatetodeals
{
yourViewController *d = [[yourViewController alloc]initWithNibName:@"yourView" bundle:nil];
[self.navigationController pushViewController:yourViewController animated:YES];
}
您需要使用performSelectorInBackground什麼的。因爲您在1方法中使用調用,所以用戶界面沒有機會進行更新,因此您看不到活動指示器。
因此,對於您的情況:
[activityindicator startanimating]; [self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[self performSelectorInBackground:@selector(stopAnimating) :nil];
然後創建一個方法:
-(void)stopAnimating
{
[activityindicator stopanimating];
}
你可以使用睡眠或東西(如睡眠(1)),以顯示activityindicator因爲剛剛出他們當你推一個視圖不會做它,因爲它在沒有時間做...
希望這有助於!
我覺得推動畫太快,顯示動畫,你立即停止。因此,你無法注意到它 – visakh7 2011-05-04 06:49:33