Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.objective-c > #184 > unrolled thread
| Started by | Ronaldo Bahia <ronaldo@jobconvo.com> |
|---|---|
| First post | 2015-09-10 17:28 -0700 |
| Last post | 2015-09-15 09:28 -0700 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.objective-c
Help with Objective C delegate not working Ronaldo Bahia <ronaldo@jobconvo.com> - 2015-09-10 17:28 -0700
Re: Help with Objective C delegate not working "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-09-11 04:07 +0200
Re: Help with Objective C delegate not working Ronaldo Bahia <ronaldo@jobconvo.com> - 2015-09-11 08:03 -0700
Re: Help with Objective C delegate not working "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-09-12 01:12 +0200
Re: Help with Objective C delegate not working Ronaldo Bahia <ronaldo@jobconvo.com> - 2015-09-15 09:28 -0700
| From | Ronaldo Bahia <ronaldo@jobconvo.com> |
|---|---|
| Date | 2015-09-10 17:28 -0700 |
| Subject | Help with Objective C delegate not working |
| Message-ID | <b27bb642-10d2-40fa-8e8c-de3843ac7c18@googlegroups.com> |
I'm learning objective c and need help to understand delegate. I have a UITextField in the FirstViewController and I want to show the text inputed in the SecondViewController. But it's not working. What am I doing wrong? Here is the thread: http://stackoverflow.com/questions/32513570/objective-c-text-field-with-delegate-not-working Thanks in advance Ronaldo
[toc] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2015-09-11 04:07 +0200 |
| Message-ID | <87bnd9909l.fsf@kuiper.lan.informatimago.com> |
| In reply to | #184 |
Ronaldo Bahia <ronaldo@jobconvo.com> writes: > I'm learning objective c and need help to understand delegate. > > I have a UITextField in the FirstViewController and I want to show the > text inputed in the SecondViewController. > > But it's not working. What am I doing wrong? > > Here is the thread: > > http://stackoverflow.com/questions/32513570/objective-c-text-field-with-delegate-not-working It would be easier if you copy-pasted the text here, along with the sources. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
[toc] | [prev] | [next] | [standalone]
| From | Ronaldo Bahia <ronaldo@jobconvo.com> |
|---|---|
| Date | 2015-09-11 08:03 -0700 |
| Message-ID | <b0b30d8e-22e5-488e-be98-143ed73ef00b@googlegroups.com> |
| In reply to | #185 |
Here is my code:
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *accessButton;
@property (weak, nonatomic) IBOutlet UITextField *codeField;
@property (nonatomic, retain) NSString *getCodeString;
@end
SecondViewController.h
#import <UIKit/UIKit.h>
@class CodeField;
@protocol CodeFieldHandlerDelegate <NSObject>
@property NSString *saveCodeString;
@end
@interface SecondViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *candidateLabel;
@property (weak, nonatomic) id <CodeFieldHandlerDelegate> myDelegate;
@end
FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface FirstViewController ()
<CodeFieldHandlerDelegate>
@property (nonatomic, strong) SecondViewController *secondViewController;
@end
@implementation FirstViewController
@synthesize getCodeString;
@synthesize secondViewController;
@synthesize saveCodeString;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)accessButton:(UIButton *)sender {
//get the input data from text field and store into string
getCodeString = self.codeField.text;
//go keypad back when button clicked from textfield
[self.codeField resignFirstResponder];
secondViewController = [[SecondViewController alloc] init];
secondViewController.myDelegate = self;
[self.navigationController pushViewController:secondViewController animated:YES];
}
// name of this string is the same of the NSString in the delegate
- (NSString *) saveCodeString {
return getCodeString;
}
@end
And SecondViewController.m
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize candidateLabel;
@synthesize myDelegate;
- (void)viewDidLoad {
[super viewDidLoad];
self.candidateLabel.text = [myDelegate saveCodeString];
}
@end
Em quinta-feira, 10 de setembro de 2015 23:07:37 UTC-3, Pascal J. Bourguignon escreveu:
> Ronaldo Bahia <ronaldo@jobconvo.com> writes:
>
> > I'm learning objective c and need help to understand delegate.
> >
> > I have a UITextField in the FirstViewController and I want to show the
> > text inputed in the SecondViewController.
> >
> > But it's not working. What am I doing wrong?
> >
> > Here is the thread:
> >
> > http://stackoverflow.com/questions/32513570/objective-c-text-field-with-delegate-not-working
>
> It would be easier if you copy-pasted the text here, along with the
> sources.
>
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk
[toc] | [prev] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2015-09-12 01:12 +0200 |
| Message-ID | <878u8c7doy.fsf@kuiper.lan.informatimago.com> |
| In reply to | #186 |
Ronaldo Bahia <ronaldo@jobconvo.com> writes:
> Em quinta-feira, 10 de setembro de 2015 23:07:37 UTC-3, Pascal J. Bourguignon escreveu:
>> Ronaldo Bahia <ronaldo@jobconvo.com> writes:
>>
>> > I'm learning objective c and need help to understand delegate.
>> >
>> > I have a UITextField in the FirstViewController and I want to show the
>> > text inputed in the SecondViewController.
>> >
>> > But it's not working. What am I doing wrong?
viewDidLoad is not called by alloc or init. It's called when you load
the view from a Nib file.
In your case, it's never called.
You should explicitely call a method of your SecondViewController to
give it the text to display. In this case, you don't need a delegate.
in SecondViewController:
-(void)setText:(id)newText {
self.candidateLabel.text=newText;
}
and in FirstViewController:
secondViewController = [[SecondViewController alloc] init];
[secondViewController setText:getCodeString];
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
[toc] | [prev] | [next] | [standalone]
| From | Ronaldo Bahia <ronaldo@jobconvo.com> |
|---|---|
| Date | 2015-09-15 09:28 -0700 |
| Message-ID | <d0b05d46-c58d-42d4-bc85-b4e449aba9eb@googlegroups.com> |
| In reply to | #187 |
Thanks a lot.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.objective-c
csiph-web