該問題涉及在UINavigation控制器樣式中使用許多視圖的應用程序。代理中的MFMailComposeViewController
我有我委託一個簡單的功能,可以通過所有視圖可用於繪製出錯誤信息
//在Appdelegate.m現在
-(void)popErrorWindow:(NSString *)theError
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:theError
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Report",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
NSLog(@"report");
[self mailIt:@"error name"];
}
}
,希望有一種機制,將與一些其他數據一起發送電子郵件的錯誤我已經創造了這個:
-(void)mailIt:(NSString *)theError {
NSLog(@"Mail it");
pickerMail = [[MFMailComposeViewController alloc] init];
pickerMail.mailComposeDelegate = self;
[pickerMail setSubject:@"error via email"];
NSMutableString *body = [NSMutableString string];
[body appendString:@"Error XXX "];
[pickerMail setMessageBody:body isHTML:YES];
// Problem here:
[self.window presentModalViewController:pickerMail animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Problem here:
[self.window dismissModalViewControllerAnimated:YES];
//NSLog(@"mail was sent");
}
的問題是在self.window,這是不是從委託訪問的正確方法, 我仍然希望在委託中具有郵件元素,因爲所有視圖都可以調用錯誤警報,並且我希望只有一個位置用於此機制。
我應該怎樣從委託內部做些什麼來取代self.window?
那麼:[self.window presentModalViewController:pickerMail animated:YES]; – chewy
我已編輯我的回答 – klefevre
致謝至此kl94, 加入:[self.navigationController.parentViewController presentViewController:pickerMail]; 我得到的錯誤: 語義問題:方法'-presentViewController:'未找到(返回類型默認爲'id') – chewy