2013-10-04 34 views
1

我正在顯示一個progressview和一個標籤,將它作爲子視圖添加到一個alertview中,並且IOS6正常工作,我在IOS7上測試了同樣的東西,並且progressview和label沒有獲取顯示。下面是我的代碼。需要做些什麼改變才能在ios7上運行?progressview沒有顯示在ios7中

alert = [[UIAlertView alloc] initWithTitle:@"Please Wait..Downloading reports..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ; 
alert.frame=CGRectMake(50, 50, 280, 40); 
prgView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar]; 
prgView.frame = CGRectMake(10, 60, 265, 20); 
prgView.hidden=NO; 
[alert addSubview:prgView]; 
statusLabel = [[UILabel alloc] init]; 
statusLabel.backgroundColor = [UIColor clearColor]; 
statusLabel.textColor = [UIColor whiteColor]; 
statusLabel.font = [UIFont fontWithName:@"AmericanTypewriter-Condensed" size:18.0]; 
statusLabel.frame = CGRectMake(120, 80, 80, 20); 
[alert addSubview:statusLabel]; 
[alert show]; 
+1

你不允許任何子視圖添加到從iOS7了'UIAlertView'或'UIActonSheet',你應該找到另一種方式。 – holex

+0

oh..ok ..謝謝holex ..你知道背後的原因是什麼嗎? – RockandRoll

+0

我認爲它與用戶隱私有關,因爲許多應用程序都有這樣的訣竅:沒有用戶的明確願望,他們自動選擇了這個或那個選項(不僅在UIAlertView中),這不是真正公平的行爲,例如在IAP的情況下;所以我想他們喜歡限制對系統相關控制的訪問,這將是程序的開始。 – holex

回答

1

嘗試使用showInView代替addSubview

[alert showInView:self.view]; 
+0

我在UIAlertView中找不到「ShowInView」方法,你是怎麼做到的? – wormlxd

0

比OP略有不同,增加了對那些誰通過搜索找到這一點。 在我的情況下,UIProgressBar被添加到UIView而沒有指定Y偏移量。在iOS6下,這顯示在導航欄下方,但在iOS7下,進度欄位於導航欄後面。我通過設置進度欄架Y中的導航欄的Y +高度的解決了這個問題:

CGRect navframe = [[self.navigationController navigationBar] frame]; 
CGFloat yloc = (navframe.size.height + navframe.origin.y); 

UIProgressView *progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar ]; 
CGRect pbFrame = progressBar.frame; 
CGRect vFrame = self.view.frame; 
pbFrame.size.width = vFrame.size.width; 
pbFrame.origin.y = yloc; 
progressBar.frame = pbFrame; 

[self.view addSubview:progressBar];