Displaying a TextField in Main UIView from a Button Pressed in UIPopover
I'm trying to Get a Textfield to display once I've pressed a button that is inside a UIPopover, I've tried a few ways with no luck. I was wondering if anyone might be able to point me in the right direction? Thanks!
I'm trying to Get a Textfield to display once I've pressed a button that is inside a UIPopover, I've tried a few ways with no luck. I was wondering if anyone might be able to point me in the right direction? Thanks!
A popover presents a view controller in a unique way. You can set up buttons in that view controller that have IBActions associated with them.
What I've done is to create a custom subclass of UIViewController that takes a delegate. I defined a protocol that the view controller uses to communicate user actions and choices. You might have "buttonAPressed" and "buttonBPressed" delegate messages. You create a view controller, set yourself up as it's delegate, and invoke it in a popover. When the user clicks buttons in the view controller, it invokes delegate messages to tell you about the user's actions.
In your case, you could put code in a "buttonAPressed delegate method that would display your text field.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
A popover presents a view controller in a unique way. You can set up buttons in that view controller that have IBActions associated with them.
What I've done is to create a custom subclass of UIViewController that takes a delegate. I defined a protocol that the view controller uses to communicate user actions and choices. You might have "buttonAPressed" and "buttonBPressed" delegate messages. You create a view controller, set yourself up as it's delegate, and invoke it in a popover. When the user clicks buttons in the view controller, it invokes delegate messages to tell you about the user's actions.
In your case, you could put code in a "buttonAPressed delegate method that would display your text field.
Ok thanks for the advice. I think I understand where your coming from as I've already set up a delegate protocol for the UIPopovercontroller. I'll give your method a go, Cheers for your help!
I tried the way you mentioned but I don't think I fully understand. What I've done is create a delegate in the UIViewController.h that I'm using as a UIPopover like this:
I tried the way you mentioned but I don't think I fully understand. What I've done is create a delegate in the UIViewController.h that I'm using as a UIPopover like this:
Can you see where I'm going wrong? Sorry to pester you it's just I can't seem to fix this and it's driving me mad!
Your setup looks mostly right. However, your view controller needs to have it's own implementation of the buttonAPressed method.
Here's what would happen:
Main view controller creates a PopovertextboxView object.
It sets itself as the delegate, and invokes it in a popover.
The user taps button A in the popover. That invokes a buttonAPressed method inside the PopovertextboxView class implementation. That method could instance variables (say you have a "sendDelegateMessages" boolean that lets you turn off message sending to your delegate.)
Your PopovertextboxView class's buttonAPressed method can do whatever it needs to do, and then send a buttonAPressed message to your delegate.
The button action in PopovertextboxView might look like this:
Code:
- (IBAction) buttonAPressed;
{
if (sendDelegateMessages)
[delegate buttonAPressed];
}
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Your setup looks mostly right. However, your view controller needs to have it's own implementation of the buttonAPressed method.
Here's what would happen:
Main view controller creates a PopovertextboxView object.
It sets itself as the delegate, and invokes it in a popover.
The user taps button A in the popover. That invokes a buttonAPressed method inside the PopovertextboxView class implementation. That method could instance variables (say you have a "sendDelegateMessages" boolean that lets you turn off message sending to your delegate.)
Your PopovertextboxView class's buttonAPressed method can do whatever it needs to do, and then send a buttonAPressed message to your delegate.
The button action in PopovertextboxView might look like this:
Code:
- (IBAction) buttonAPressed;
{
if (sendDelegateMessages)
[delegate buttonAPressed];
}
That's great thanks for the quick reply, I think I should be able to fix it now. Thanks so much