我的iPad應用程序有一個奇怪的問題。UIActionSheet第一次顯示正常,第二次不正確
當應用程序啓動時,我可以點擊一個條形按鈕項目以顯示UIActionSheet,並通過所有按鈕選項和標題從條形按鈕項目正常顯示動作表。然而,如果我從這張表中選擇一個動作,它使用presentViewController來顯示另一個非常簡單的視圖控制器,當視圖控制器自行解散時,如果我點擊與之前相同的條形按鈕項,我會得到一個不正確的動作表。這裏是動作片酥料餅的樣子:
動作片的高度是該訴訟片應該有選擇的號碼是否正確,但它是類的標題,所有的按鈕文本爲空或零。但是,在創建操作表之後,我記錄了每個按鈕和按鈕文本的數量,並且從第一次到第二次看起來都一樣。
我是最新的Xcode和SDK,並且該應用的目標是iOS 5.0或更高版本。關於發生了什麼的任何想法?
編輯:這是一些代碼。可能有一些異常(語法和格式明智),因爲我不得不砍掉一堆與此問題無關的代碼。
的IBAction爲爲維護按下按鈕:
-(IBAction) cmdMaintenance_Click:(id)sender
{
self.maintenanceActionSheet = [[[UIActionSheet alloc] initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Backup", @"About", nil] autorelease];
_maintenanceActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
_maintenanceActionSheet.tag = MAINTENANCE_OPTIONS;
NSLog(@"Number of buttons: %d", _maintenanceActionSheet.numberOfButtons);
for (int idx = 0; idx < _maintenanceActionSheet.numberOfButtons; idx++)
{
NSLog(@"Sheet button %d: %@", (idx + 1), [_maintenanceActionSheet buttonTitleAtIndex:idx]);
}
[_maintenanceActionSheet showFromBarButtonItem:cmdMaintenance animated:NO];
}
和動作片的代表:
-(void)actionSheet:(UIActionSheet*)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex != [actionSheet cancelButtonIndex])
{
if(buttonIndex == OPTIONS_ABOUT)
{
if(aboutView == nil)
{
aboutView = [[AboutViewController alloc] initWithNibName:@"AboutView-iPad" bundle:nil];
aboutView.title = [MyAppDelegate translateString:@"About"];
}
[self presentViewController:aboutView animated:YES completion:nil];
}
}
}
在我關於視圖控制器,完成按鈕代碼:
-(IBAction)done:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
編輯2:最後一個註釋...如果我用aboutView註釋掉對presentViewController的調用,acti在工作表上正確返回。
編輯3:這裏的問題歸結爲這個......世界上的什麼可能會導致UIActionSheet顯示彈出像我所看到的?我的主視圖控制器還有其他顯示UIActionSheet的區域來請求用戶反饋(如刪除客戶),而這些其他區域顯示與「維護」按鈕相同的行爲,即真正垂直薄的操作表單。
編輯4:我把我的視圖控制器這種額外的代碼,試圖獲得關於正在發生的事情(和試圖影響動作片的大小)的更多信息:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"willPresentActionSheet with frame %@ and bounds %@", NSStringFromCGRect(actionSheet.frame),
NSStringFromCGRect(actionSheet.bounds));
CGRect rect = actionSheet.frame;
rect.size.width = 400.0;
actionSheet.frame = rect;
}
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"didPresentActionSheet with frame %@ and bounds %@", NSStringFromCGRect(actionSheet.frame),
NSStringFromCGRect(actionSheet.bounds));
}
的試圖改變動作片的框架不具有當然的作用,這裏是在控制檯輸出從上述:
2013-07-15 19:32:58.662 MyApp[12953:907] willPresentActionSheet with frame {{0, 0}, {272, 341}} and bounds {{0, 0}, {272, 341}}
2013-07-15 19:32:58.677 MyApp[12953:907] didPresentActionSheet with frame {{0, 0}, {272, 327}} and bounds {{0, 0}, {272, 327}}
2013-07-15 19:33:08.075 MyApp[12953:907] willPresentActionSheet with frame {{0, 0}, {0, 324}} and bounds {{0, 0}, {0, 324}}
2013-07-15 19:33:08.080 MyApp[12953:907] didPresentActionSheet with frame {{0, 0}, {0, 310}} and bounds {{0, 0}, {0, 310}}
的前兩行是從當它被正確工作,並且作爲可以從後面兩行看到,對於某些re,操作表的寬度爲0一個兒子。
你能表現出一定的代碼。 – Fogmeister
我在裏面放了一些代碼,但是我沒有看到可以出錯的一大堆代碼。這是非常簡單的東西。 –
您不應該在提供的控制器上調用'dismissViewControllerAnimated',而是在文檔中所述的呈現控制器上調用'dismissViewControllerAnimated'。試試看看是否能解決你的問題。 – ludesign