我相信這是一個相當簡單的應用程序,目前基於一些教程拼湊在一起。我在OSX 10.6.4中使用XCode 3.2.3。它開始作爲一個標準的iPhone「基於窗口的應用程序」。使用Interface Builder我在這裏使用O'Reilly的視頻教程,增加了標籤欄控制器:iPhone應用程序中的例外情況:Modal轉換已在進行中
http://broadcast.oreilly.com/2009/06/tab-bars-and-navigation-bars-t.html
第一個選項卡我有一個標準的UIView有兩個按鈕。無論調用同一個函數來顯示的UIImagePickerController:
-(IBAction) btnPhotoClicked:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if((UIButton *)sender == btnChoosePhoto)
{
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
我運行一個仿真器內部的代碼,所以永遠只能點擊稱爲按鈕選擇照片。當對話框發佈時選擇了該功能:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
if (mediaUrl == nil)
{
imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
if(imagePuzzle == nil)
{
//--- Original Image was selected ---
imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
}
else {
//--- Get the edited image ---
//--- If it was successful the above valueForKey:UIImagePickerControllerEditedImage
//--- would have assigned it already.
}
}
else {
//--- Muppet selected a video
}
// Animate the picker window going away
[picker dismissModalViewControllerAnimated:YES];
ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.delegate = self;
[self presentModalViewController:imageViewController animated:YES];
[imageViewController release];
}
這是我的問題所在。我已經嘗試了許多不同的黑客和迭代,但上面的代碼是最簡單的問題展示。當imageViewController顯示爲模式對話框時,會拋出以下異常:
2010-07-09 15:29:29.667 Golovomka[15183:207] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal
transition from <NewViewController: 0x5915f80> to <ImageViewController: 0x594a350>
while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear
to know the current transition has completed'
如何解決此問題?我嘗試過延遲和其他技巧,但並不真正瞭解我應該如何使用viewDidAppear或viewDidDisappear來幫助我。還值得注意的是,一個非常基本的應用程序加載選擇器,然後顯示另一個視圖與圖像不會產生錯誤。任何幫助感激地收到。
謝謝你的建議,我會盡力,在我的代碼,它比我在做什麼整潔。在用戶拍攝照片或選擇照片後,我正在推動模式視圖。這裏的想法是,有一些潛在的激烈圖像處理,我想模式地顯示給用戶,直到它完成。所以在強制模態視圖之前需要用戶操作。撇開我最終殺死了這個異常:
– Diziet 2010-07-10 11:51:04確定picker.view.superview removeFromSuperview。真的很糟糕的解決方案,除非你喜歡之後的所有內容都是空白的!我最終使用標籤欄應用程序中的導航欄控制器從頭開始重建應用程序,並且工作正常。另一方面,你的解決方案也有效。謝謝。現在更清楚了。我從C/C++/Java/Perl/bash背景中只做了兩天。 – Diziet 2010-07-10 18:50:41