views:

33

answers:

2

I have written a code for mail application like:

{
  MFMailComposeViewController *picker=[MFMailComposeViewController alloc] init];
  .........
  .........
  [self.navigationController pushViewController:picker.view animated:YES]; 
}

The view is not getting loaded.Is is mandatory to write

[self presentModalViewController:picker animated:YES];

because when I write the above line it works perfectly fine.

A: 

Do you use a navigation controller in your application?

charith
A: 

do you actually have a navigation controller? You need to give more background information like what the class's superclass that contains the code you posted is. presenting a view modally and in a navigation stack is very different.

A modal view slides up from the bottom of the screen and fills the entire screen so that you can only do the one action that view lets (it hides things like navigation bars and tab bars) (like adding a new event in the calendar app)

a navigation controller is most commonly used with table views and slides the old view off to the left and the new view on from the right (like the settings app)

From the look of the code you posted you are wanting to present the View modally and you don't need the line where you push the view onto the screen using a navigation controller (which I'm guessing doesn't exist?)

ALSO: This line of code is incorrect anyway:

[self.navigationController pushViewController:picker.view animated:YES];

presentModalViewController asks for a viewcontroller not a UIView. So you need to remove the .view after picker.

Jonathan
@JonathanThanks a lot Jonathan for ur support.Let me explain my problem in detail.Actually I want to develop an application that sends email but do not show the interface to user.The values of all the fields will be set programatically.I also want to attach an image in that mail.Thats why I do not want to use "presentModalViewController".
anurag
Ah right, sorry I haven't looked an email and didn't realise that MFMailComposeViewController was from Apple. While you can easily set the fields programmatically, the user has to click send themselves and there is no way for the app to do this. Because even though all Apps are checked by Apple, they don't want apps that send out loads of emails, which could cost the user a lot on their data plan (Wifi or cellular). Why exactly are you trying to send an email? For a "phone-home" feature?
Jonathan
@JonathanActually I am trying to develop an app that will automatically send the email as soon as a picture is clicked from the camera.
anurag