variable usage

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

  1. macrumors newbie

    Joined:
    Feb 28, 2011
    #1
    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

    Code:
    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
    Code:
    MFMailComposeViewController
    
    Here is one IBAction for a segmented controller

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

    Code:
    - (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
    Code:
    @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

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

    in the MFMailComposeViewController method I am building emailBody like this

    Code:
    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
    Code:
    - (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

    Joined:
    Aug 28, 2008
    #2
    Here:
    Code:
     outEmailAddress = emailAddress.text;
    Definition of the textField
    Code:
    @property (weak, nonatomic) IBOutlet UITextField *outEmailAddress;
    error message
    Code:
    "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

    Code:
     [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. thread starter macrumors newbie

    Joined:
    Feb 28, 2011
    #3
    Thank you Olaf I did change that part of the code
     

Share This Page