Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2012, 10:12 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Warwickshire, England
Posts: 6
Olli177 is on a distinguished road
Default 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!
Olli177 is offline   Reply With Quote
Old 01-10-2012, 01:27 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Olli177 View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 01-14-2012, 10:17 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Warwickshire, England
Posts: 6
Olli177 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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!
Olli177 is offline   Reply With Quote
Old 01-15-2012, 10:45 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Warwickshire, England
Posts: 6
Olli177 is on a distinguished road
Default

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:
Code:
@protocol PopoverDelegate <NSObject>

- (void)buttonAPressed;

@end

@interface PopovertextboxView : UIViewController 
{      
    id <PopoverDelegate> delegate;
}

@property (nonatomic, retain) id delegate;

@end
Which I then synthesize in the .m file.
I then have my UIButton in the same .m file:
Code:
- (void)viewDidLoad
{  [super viewDidLoad];
    UIButton * addTB1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    addTB1.frame = CGRectMake(0, 0, 100, 50);
    [addTB1 setTitle:@"Textbox One" forState:UIControlStateNormal];
    [self.view addSubview:addTB1];    
    [addTB1 addTarget:self action:@selector(buttonAPressed) 
    forControlEvents:UIControlEventTouchUpInside];
    }
After adding the delegate at the top of my MainViewController.h
Code:
@interface MainViewController : UIViewController <PopoverDelegate>
I then add the buttonAPressed action in the MainViewController.m file:
Code:
- (void)buttonAPressed { 
    NSLog(@"Button Pressed");
    UITextView *textfield = [[UITextView alloc] init];
    textfield.frame = CGRectMake(50, 5, 100, 100);
    textfield.backgroundColor = [UIColor blueColor];
    [self.view addSubview:textfield];
}
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!
Olli177 is offline   Reply With Quote
Old 01-15-2012, 11:02 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Olli177 View Post
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:
Code:
@protocol PopoverDelegate <NSObject>

- (void)buttonAPressed;

@end

@interface PopovertextboxView : UIViewController 
{      
    id <PopoverDelegate> delegate;
}

@property (nonatomic, retain) id delegate;

@end
Which I then synthesize in the .m file.
I then have my UIButton in the same .m file:
Code:
- (void)viewDidLoad
{  [super viewDidLoad];
    UIButton * addTB1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    addTB1.frame = CGRectMake(0, 0, 100, 50);
    [addTB1 setTitle:@"Textbox One" forState:UIControlStateNormal];
    [self.view addSubview:addTB1];    
    [addTB1 addTarget:self action:@selector(buttonAPressed) 
    forControlEvents:UIControlEventTouchUpInside];
    }
After adding the delegate at the top of my MainViewController.h
Code:
@interface MainViewController : UIViewController <PopoverDelegate>
I then add the buttonAPressed action in the MainViewController.m file:
Code:
- (void)buttonAPressed { 
    NSLog(@"Button Pressed");
    UITextView *textfield = [[UITextView alloc] init];
    textfield.frame = CGRectMake(50, 5, 100, 100);
    textfield.backgroundColor = [UIColor blueColor];
    [self.view addSubview:textfield];
}
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];
}
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 01-15-2012, 11:13 AM   #6 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Warwickshire, England
Posts: 6
Olli177 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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

Ollie
Olli177 is offline   Reply With Quote
Reply

Bookmarks

Tags
textfield, uibutton, uipopover, uiviewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
15 members and 390 guests
AReality, bignoggins, BSH, djqbert, Duncan C, epaga, flamingliquid, jbro, jcdevelopments, leighec68, markolo, nobstudio, revg, Rudy, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0