tags:

views:

80

answers:

3

i attempt to generate a new button item once i click on a button generator, it able to generate but only will show up on the screen after relaunch the application,but i want it be generated instantly and show up at the current view,any suggestion i know is something related to the viewDidLoad function,anyway pls help

+2  A: 

Lets say this is your view controller method that creates buttons:

-(void)generateButton:(id)sender {
  UIButton *button = [UIbutton alloc] initWithFrame:CGRectMake(50, 50, 100, 40)];
  [self.view addSubview:button];
  [button release];
}

In order to be visible you have to add the button as a subview of a current showing view. In this case I am adding it to the main root level view for this view controller.

Squeegy
sorry i got it because of my button add to the wrong view and not visible,ur code are right
A: 

thanks Squeengy but i think u are not really understand my question i have generated the button successfully but it will only appear when i relaunch the application(exit the current application and relaunch),i want it can be appear when i click on the button immediately

What you're describing doesn't make sense (and should be a comment on his answer). His code creates a button and displays it instantly, but that button would disappear on restart of the application unless you were somehow saving and restoring its state.
Brad Larson
Unless you post the actual code you are using to create and display the button I don;t think we can help you much more.
Squeegy
Please add more information to your question, don't add another answer just to reply. Stack Overflow is not a discussion forum.
Chris Hanson
A: 

When you add a subview to a view, it should be displayed immediately. Most likely, you're doing something very wrong which is resulting in the view not displaying when it should. Another thing, how are the views only showing up next launch? It sounds like you are actually persisting them somehow, which could be adding to the trouble caused by whatever you're doing. If this were IRC, I'd suggest you paste some code, because without that, there's little way to know what you're actually doing that could be causing so much trouble.