1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

variable usage

Discussion in 'iPhone/iPad Programming' started by jjanes, Mar 7, 2012.

  1. macrumors newbie

    I have put together an App that is a fairly nice form laid out for the IPadand all I want to do is pass the varaible content from the specific IBOutlet in the form to the emailbody of an email that the App would send out. It is built in a single view so I have several segmented controllers, and text boxes each with its own IBACTION I can use something like

    NSLog([NSString stringWithFormat:@"%@", [telephoneNum text]]);
    to see the actual content as I change it in the log file.
    but I am having difficulty passing the information to the main email build functionality
    Here is one IBAction for a segmented controller

    - (IBAction)timeFrameAnswer:(id)sender {
        NSLog(@"Time Frame");
        switch (timeFrame.selectedSegmentIndex) {
            case 0:
                outTimeFrame = @"ASAP";
            case 1:
                NSLog(@"1-3 Months");
                outTimeFrame = @"1-3 Months";
            case 2:
                NSLog(@"3-6 Months");
                outTimeFrame = @"3-6 Months";
            case 3:
                NSLog(@"6+ Months");
                outTimeFrame = @"6+ Months";
    and a textbox IBAction

    - (IBAction)emailAnswer:(id)sender {
        NSLog(@"Email Address");
        NSLog([NSString stringWithFormat:@"%@", [emailAddress text]]);
        outEmailAddress = emailAddress.text;
        [emailAddress resignFirstResponder];
    I have been trying to follow along in several tutorials on how to get this done but I am at a brick wall right now
    the MFMailComposeViewController has a variable in it call emailBody and I need to load each one of these responses into this variable which I can do once I know what the syntax is to properly get the different variable contents.

    I created in the .h file I have created many variables similar to this
    @property (weak, nonatomic) IBOutlet UITextField *outTimeFrame;
    @property (weak, nonatomic) IBOutlet UITextField *outEmailAddress;
    and the corresponding @synthesize in the .m file in hopes that this was the correct process

    @synthesize outTimeFrame;
    @synthesize outEmailAddress;
    and I do release them in the didunload method

    in the MFMailComposeViewController method I am building emailBody like this

    NSString *emailBody = [NSString stringWithFormat:@"Time Frame: %@\nEmail: %@",self.outTimeFrame, self.outEmailAddress];
    I think I am I close in my coding shown here but am just missing some type of syntax or something simple.

    One other strange thing currently I enter text into one of the textboxes that has a space like "Mickey Mouse" I see the full string in the log file but shows in the emailBody is null if I simply enter "Mickey" then "Mickey" shows in the emailBody.

    this I know happens in the piece
    - (IBAction)fullNameAnswer:(id)sender {
        NSLog(@"Full Name");
        NSLog([NSString stringWithFormat:@"%@", fullName.text]);
        outFullName = fullName.text;    
        [fullName resignFirstResponder];
    I do see some warnings throughout the IBACTION pieces of code that say this
    "Incompaitible pointer types assigning to UITextField * weak from NSString *"

    The one just above fullNameAnswer however is clean of warnings

    Please give me some detailed assistance if possible.
    Thanks Jeff
  2. macrumors regular

     outEmailAddress = emailAddress.text;
    Definition of the textField
    @property (weak, nonatomic) IBOutlet UITextField *outEmailAddress;
    error message
    "Incompaitible pointer types assigning to UITextField * weak from NSString *"
    You are treating a Textfield like a string and that is what the error message it trying to tell you. It should be

     [outEmailAddress setText:emailAddress.text];
    A recommendation wrt naming: if something is a textfield then name it textField, if it's a string name it string. That way reducing confusion what kind of object hide behind a name.

    - Olaf
  3. macrumors newbie

    Thank you Olaf I did change that part of the code

Share This Page