UIButton switch views, and display text...

Discussion in 'iOS Development' started by timcreasy37, Jul 27, 2009.

  1. timcreasy37

    timcreasy37 New Member

    Joined:
    May 27, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    I have looked all over and cannot seem to find this.

    I created a simple application with two views. On the first view there is a text field and a button. When the button is pressed it takes you to the second view AND I would like it to display what was in the text field, in a blank label on the second page. I just cannot seem to be able to do this. Any help would be greatly appreciated.

    Thanks
    --Tim
  2. ipodgreatmaster

    ipodgreatmaster Member

    Joined:
    Feb 20, 2008
    Messages:
    186
    Likes Received:
    0
    Device:
    4G iPod touch
    Use NSUserDefaults
  3. timcreasy37

    timcreasy37 New Member

    Joined:
    May 27, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Can someone please go into detail on how I can do this?
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Are the views both controlled by the same controller? Or, are the two views part of separate controllers?

    We can not answer because we don't know the setup of your application. Regardless, NSUserDefaults is the wrong solution.
  5. timcreasy37

    timcreasy37 New Member

    Joined:
    May 27, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    The two views are part of separate view controllers. They are accessed using the present/dismiss ModalViewController.

    Also how can I donate to this site?
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Override the viewController's initMethod to include new parameters that pass the values you want. In that method, set the values accordingly. Then simply present the view controller as you would any other modal view controller.
  7. timcreasy37

    timcreasy37 New Member

    Joined:
    May 27, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    What would be an example of this? Mind you I am very new to this. Would I want to change initWithNibName:nil or bundle:nil?
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    [OBJC]
    - (id)initWithNibName

    Please Register or Log in to view images

    NSString *)nibNameOrNil bundle

    Please Register or Log in to view images

    NSBundle *)nibBundleOrNil andText

    Please Register or Log in to view images

    NSString *)text {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    if (text != nil)
    someLabel.text = text;
    }
    return self;
    }[/OBJC]

    When you create the viewController, you would call the above method instead of initWithNibName:bundle:.
  9. timcreasy37

    timcreasy37 New Member

    Joined:
    May 27, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Is there anyway you could just build me a simple application with two views. A textfield and button on the first view. And on the second the label where the text from the textfield will be displayed, and a back button to go back to the first view. I would be extremely grateful and could pay you a couple of bucks via paypal or something for your trouble

Share This Page