MFMailComposeViewController address book picker customization - iphone

Is it possible to customise the behavior of how the ABPeoplePickerNavigationController is displayed modally from the MFMailComposeViewController whenever a user presses the '+' icon in the 'To:' and 'Cc/Bcc:' fields?
I want to wrap the ABPeoplePickerNavigationController inside of another view controller before it is being presented modally. How do I do this?

What kind of functionality are you looking to add by wrapping the PeoplePicker in another view controller?
You can display the PeoplePicker with the following code:
ABPeoplePickerNavigationController *ab = [[ABPeoplePickerNavigationController alloc] init];
[ab setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
[ab setPeoplePickerDelegate:self];
[self presentModalViewController:ab animated:YES];
You may need to subclass ABPeoplePickerNavigationController depending on what you need to do.

Related

How to Open Addressbook New Contact Screen

In my application I have UIBarButtonSystemItemAdd on right side of the navigation controller. On tapping of that plus icon I want to open address book in editable mode. Please refer the following image.
How to open address book UI for new contact in editable mode directly?
In the AddressBookUI.framework, there is a class called ABNewPersonViewController. Basically, what you want to do is this:
ABNewPersonViewController *abnpvc = [[ABNewPersonViewController alloc] init];
[abnpvc setNewPersonViewDelegate: self];
[self presentViewController: abnpvc animated: YES completion: nil];
This brings up the view you are looking for.

How come presentModalViewController is not working the second time?

I am using a tab based application that shows a presentModalViewController called "overview" that has 2 buttons on it .
In order to call it I am using the following code in app delegate:
Overview *overview = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
[self.tabBarController presentModalViewController:overview animated:YES];
When overview shows up, it has a button called that gets clicked and I am using the following code:
-(IBAction) btnLoginPressed{
[self dismissModalViewControllerAnimated:YES]; //get rid of view
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self.tabBarController presentModalViewController:login animated:YES];
[login release];
}
However the login prsentModalViewController never shows up. Can someone explain why and what I can do to show it?
Thanks
When you present a modal view controller, you do it from the view controller currently in the view.
Assuming your second modal display of a view controller is happening in Overview.m change your code to the following:
-(IBAction) btnLoginPressed {
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self presentModalViewController:login animated:YES];
[login release];
}
You don't need to dismiss Overview first, and in fact you shouldn't as it the animations won't work in conjunction with each other.
When you ultimately dismiss login (or however deep you want to go), you send dismissModalViewController:animated: as high up as you need to. To get back to the tab bar's controller use:
[self.tabBarController dismissModalViewController:animated]
It would be well beyond the scope of your question and the time I have to answer but you should take some time and really study the docs on implementing View Controllers. I definitely recommend following Apple's code style guidelines as one suggestion to make your code much more readable (e.g. overviewViewController vs overview). It's also clear you're just learning so keep at it.

Previous View after dismissModalViewControllerAnimated of email function somehow defect

i am trying and trying.... but no result yet.
i have a view with a navigationcontroller and -bar. in addition there is a tableview.
if you click on a row, the iphone email function is getting startet by using the email example from apple (MailComposerViewController.h and .m).
it opens and i am able to send or cancel the mail. after that the "dismissModalViewControllerAnimated" methode is dismissing the emailing view. everything looks right, i am in the previous view now, BUT:
when i want to use buttons from the navigationitem or if i want to add rows to the tableview, the app is crashing without any error message.
do i have to set something back or to "remove" something which is still there because of the mailing view?
it's really strange and i am searching now for hours....... :-(
thank you very much in advance!
hopefully someone has an idea.
EDIT:
ok, here i have the code now:
in a tableview which is included in a navcontroller i have following lines to open first a Subclass of UIViewController:
- (IBAction)Action:(id)sender
{
DetailViewController *editViewController = [[DetailViewController alloc] initWithNibName:#"TripDetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:editViewController animated:YES];
editViewController.navigationItem.prompt = #"Details";
[editViewController release];
}
in the DetailViewController following action is processed when the user clicks on the button:
- (IBAction)mailTrip:(id)sender {
MailComposerViewController *mailComposer = [[MailComposerViewController alloc] init];
[[[self view] window] addSubview:[mailComposer view]];
[mailComposer showPicker:sender];
}
when i press the related button, the MailComposerViewController pushes up correctly. all functions of the MailComposerViewController are working correct.
but when i send or cancel the mail and the MailComposerViewController disappears, my previous view doesn't work anymore.
in the MailComposerViewController-Example from apple the MailComposerViewController just disappear and the previous view is working fine again.... :-(
ok, i found the stupid simple problem.
the MailComposer-View was after dismissing it still over the previous view.
i did set the propert hidden after dismissing and now it works...
[self dismissModalViewControllerAnimated:YES];
[[self view] setHidden:YES];
but i am really not sure if this is the right way to do it...

Click Tabbar to Open Email view in iphone

HI,
I am new to iphone development.I have created the tabbar programmatically and sets five views in the tabbar. Now i want to load an email application view when i clicked the tabbar.This works properly.When i clicked the next tabbar and come back to the email view, i am able to see the normal view and not the Email view.Only one time i am able to see my mail application.I have mail application in the viewDidLoad method. So please guide me.
Here is my code,
- (void)viewDidLoad {
[super viewDidLoad];
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mail setToRecipients:[NSArray arrayWithObjects:#"aaa#gmail.com",nil]];
[mail setSubject:#"Title"];
[self presentModalViewController:mail animated:NO];
}
[mail release];
}
Thanks.
viewDidLoad only runs after the nib file has been loaded, which is once the first time the viewController is shown and then once after any memory warnings are sent.
You want to use viewDidAppear: instead which is called every time after the viewController comes into view.
If you use viewDidAppear method it will be keep on calling the mail view.So use viewWillAppear method.

Reusing a MFMailComposeViewController

I have an app that is built on the TabBar-based app in which I need to have one tab that is basically an email composer. So I'm trying to use a MFMailComposeViewController as one of the tabs. This seems to work fine until I actually go to send an email with the controller. If I do this the MFMailComposeViewController's view disappears and can't be used again.
If I'm reading the docs correctly, the MFMailComposeViewController is normally used modally, but it is supposed to work non-modally as well.
This is how I am adding it to the tab bar...
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.title = #"Feedback";
mailController.tabBarItem.image = [UIImage imageNamed:#"pencil.png"];
[array addObject:mailController];
tabBarController.viewControllers = array;
You you using
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
and hides it with
[self dismissModalViewControllerAnimated:YES];
If so then just comment dismissing.