我創建了一個類來啓動MailComposer,這樣我的iPhone應用程序在生成各種電子郵件時只有一個地方可用:一些帶附件,一些不帶。有些預填充地址,有些則不是。iPhone MailComposer類UIViewController dismissModalViewControllerAnimated問題
我不希望我的類實現UIViewController,但它必須這樣才能成爲MailComposer的代理。否則,調用我的類的視圖控制器本身必須是MailComposer的委託,這違背了目的。
讓我的課程成爲視圖控制器的不利之處在於它必須先加載到屏幕上,然後才能調出MailComposer。不幸的是,視圖控制器不能透明。效果是,在MailComposer出現之前,屏幕上的任何內容都會被純白色視圖控制器覆蓋一段時間。
我也許可以活下去,但不是這樣:在MailComposer消失後,我剩下我的空白視圖控制器佔據屏幕。我應該通過調用這是能夠得到來自內部自身擺脫它:
[self.parentViewController dismissModalViewControllerAnimated:NO];
但是,死一個可怕的死亡:「裝43365個堆棧幀......」
有我的課 - 一個UIViewController預填充然後啓動一個MailComposer--丟失了它的parentViewController的軌跡?這不是零,因爲我已經測試過了。
從當前視圖控制器內推出...
// My class is called Email.
Email *oEmail = [[[Email alloc] init] retain];
// Red, to remind myself that I'd like to someday learn to make it transparent.
oEmail.view.backgroundColor = [UIColor redColor];
// Pre-fill whatever fields you want, and specify attachments.
oEmail.EmailSubject = @"I am truly stumped";
// This has to go on screen first.
[self presentModalViewController:oEmail animated:NO];
// Then this can happen, which brings up the MailComposer.
[oEmail f_SendEmail];
// Commenting out the next line didn't help, so I turned it back on.
[oEmail release];
類裏面,你需要的mailComposeController:didFinishWithResult:錯誤:方法使MailComposer走,並要做到這一點,則類必須是MFMailComposeViewControllerDelegate。這裏發生了什麼:
// This gets rid of the mail composer.
[self dismissModalViewControllerAnimated:YES];
// This never fails to get rid of other modal view controllers when called
// from within those controllers, but boy does it not work here.
[self.parentViewController dismissModalViewControllerAnimated:NO];
如果你能幫助我,我將真正感謝!
請注意,「加載43365堆棧幀...」表示無限遞歸。如果你看看調試器,你應該看到造成這種情況的方法週期。 – 2010-04-01 12:23:13
另外,「視圖控制器不能透明」在技術上是錯誤的。視圖控制器只是管理視圖邏輯的對象。視圖本身可以是透明的,半透明的或非全屏的。你所指的是-presentModalViewController:animated:方法,它在你的控制器視圖背後放置一個不透明的白色視圖,當它滑動到屏幕上時。 – 2010-04-01 12:26:46