creating programatic buttons in nib navigation controller view

Discussion in 'iOS Programming' started by massive.boisson, Dec 27, 2008.

  1. massive.boisson
    Expand Collapse
    macrumors newbie

    Joined:
    Dec 27, 2008
    #1
    Hi,

    I've created NIB file for one ViewController on my Navigation Controller. It opens up and shows empty white view. I want to show UIButtons on it programatically.
    I overwrite viewDidLoad method, and can see it gets called. I create a button, but am not able to attach that button to view.

    I've tried numerous ways, but this is one of them:
    Code:
    	UIButton *myButton = [self makeMyButton];
    	[button setCenter:CGPointMake(160.0f, 200.0f)];	
    	self.view = myButton;
    	[button release];
    
    Any help really appreciated.

    Thanks in advance

    --MB
     
  2. stadidas
    Expand Collapse
    macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #2
    Try:

    Code:
    [[self navigationItem] setRightBarButtonItem:myButton];
    
     
  3. ghayenga
    Expand Collapse
    macrumors regular

    Joined:
    Jun 18, 2008
    #3
    Will that work if he's creating a UIButton and nota UIBarButtonItem?

    I would just use

    [self.vew addSubview:myButton];
     
  4. ghayenga
    Expand Collapse
    macrumors regular

    Joined:
    Jun 18, 2008
    #4
    At least I got the impression he was trying to add the button to the view and not the navigation bar.
     
  5. ghayenga
    Expand Collapse
    macrumors regular

    Joined:
    Jun 18, 2008
    #5
    Will that work if he's creating a UIButton and nota UIBarButtonItem?

    I would just use

    [self.view addSubview:myButton];
     
  6. l.sanjeevrao
    Expand Collapse
    macrumors newbie

    Joined:
    Oct 17, 2008
    #6
    Adding uibtton to nib file programmetically

    I think it does not possible to add the uibutton for nib file programmatically.
    Do one thing, just create the view programmetically and add the button to it instead of using nib file.
     
  7. natanavra
    Expand Collapse
    macrumors newbie

    Joined:
    Dec 26, 2008
    #7
    Why can't you use the nib itself...?
    anyways you can use...
    [self.view addSubview:mybutton];
    [mybutton release];

    umm... I think it's possible to manipulate a nib programatically, you hook up the nib to a UIView subclass and in it.. you initialize a button programatically in that View... in the viewDidLoad Method.
     

Share This Page