views:

46

answers:

1

The code below generates a button and places it on the screen;

button = [UIButton allow] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 20.0)]; button.frame = CGRectMake(0.0, 20.0, 10.0, 40.0); button.backgroundColor = [UIColor redColor]; [self.window addSubview:button];

However, when I generate a new screen via "pushViewController:animated" to overlap the current screen, the buttons float about the new screen. But everything else attached to the old screen via Interface builder disappears the correct way behind the new screen.

So, what am I doing wrong?

Thanks,

+2  A: 

You want to add the button to the current view, not the window underlying it. You should be creating the button in loadView of the currently visible UIViewController. Try adding it to that controller's view like this:

[self.view addSubview:button];
Hilton Campbell
All attempts to do that have failed. This is the first thing I tried. In the interface the button is labeled an UIButton *button and In the IBOutlet *button. Could this be a problem? Also, this is on the second view of a flip view. So perhaps that is confusing the issue?Thanks
nepfable
I understand what you mean by inserting in loadView. However button is attached to a IBAction to create the button and it seems to only connect to the window and not the view.I keep getting the error - Request for member view is something not a structure or member.Any further ideas would be nice.Thanks
nepfable
Can you provide the full code in your question? That will help a lot.
Hilton Campbell