PDA

View Full Version : creating programatic buttons in nib navigation controller view




massive.boisson
Dec 27, 2008, 07:32 PM
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:
UIButton *myButton = [self makeMyButton];
[button setCenter:CGPointMake(160.0f, 200.0f)];
self.view = myButton;
[button release];


Any help really appreciated.

Thanks in advance

--MB



stadidas
Dec 27, 2008, 08:51 PM
Try:


[[self navigationItem] setRightBarButtonItem:myButton];

ghayenga
Dec 28, 2008, 11:03 AM
Try:


[[self navigationItem] setRightBarButtonItem:myButton];


Will that work if he's creating a UIButton and nota UIBarButtonItem?

I would just use

[self.vew addSubview:myButton];

ghayenga
Dec 28, 2008, 11:08 AM
At least I got the impression he was trying to add the button to the view and not the navigation bar.

ghayenga
Dec 28, 2008, 11:22 AM
Try:


[[self navigationItem] setRightBarButtonItem:myButton];


Will that work if he's creating a UIButton and nota UIBarButtonItem?

I would just use

[self.view addSubview:myButton];

l.sanjeevrao
Dec 28, 2008, 12:00 PM
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.

natanavra
Dec 28, 2008, 12:14 PM
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.