 |
 |
|
 |
02-17-2009, 08:31 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Location: India
Posts: 125
|
Help with textField....accessing property in another view
Hi
I have an application with a two text fields in one view(view1) and two labels in another view ( view2). I have a button in view1, when it is pressed it loads view2 and I want to change the label to the text that i entered in the text field. How can I do it?........... i have read somewhere in the forum about delegates and all, I read in details but I was not able to figure out how to use it.
Can anyone provide me a sample code?
Thanks in Advance
-John
|
|
|
02-18-2009, 04:42 PM
|
#2 (permalink)
|
|
New Member
Join Date: Feb 2009
Posts: 8
|
Quote:
Originally Posted by JohnMabassa
Hi
I have an application with a two text fields in one view(view1) and two labels in another view ( view2). I have a button in view1, when it is pressed it loads view2 and I want to change the label to the text that i entered in the text field. How can I do it?........... i have read somewhere in the forum about delegates and all, I read in details but I was not able to figure out how to use it.
Can anyone provide me a sample code?
Thanks in Advance
-John
|
I think you are invoking the second view (view2) in the following manner.
.h file of view1
#import <UIKit/UIKit.h>
#import "View2Controller.h"
@interface View1Controller : UIViewController {
View2Controller *view2;
}
@property (nonatomic,retain) View2Controller * view2;
@end
in .m file of view2
if(self.view2 ==nil) {
View2Controller *view2Controller = [[View2Controller alloc] initWithNibName:@"View2View" bundle:[NSBundle mainBundle]];
self. view2 = view2Controller;
[view2Controller release];
[self.navigationController pushViewController:self. view2 animated:YES];
In view2, create a property by name textValue andyou can set the text field value to this property just before the the last line of code.
for eg:
view2.textvalue=myTextField.text;
[self.navigationController pushViewController:self. view2 animated:YES];
|
|
|
02-19-2009, 11:14 AM
|
#3 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Location: India
Posts: 125
|
Quote:
Originally Posted by markwilliams
I think you are invoking the second view (view2) in the following manner.
.h file of view1
#import <UIKit/UIKit.h>
#import "View2Controller.h"
@interface View1Controller : UIViewController {
View2Controller *view2;
}
@property (nonatomic,retain) View2Controller * view2;
@end
in .m file of view2
if(self.view2 ==nil) {
View2Controller *view2Controller = [[View2Controller alloc] initWithNibName:@"View2View" bundle:[NSBundle mainBundle]];
self. view2 = view2Controller;
[view2Controller release];
[self.navigationController pushViewController:self. view2 animated:YES];
In view2, create a property by name textValue andyou can set the text field value to this property just before the the last line of code.
for eg:
view2.textvalue=myTextField.text;
[self.navigationController pushViewController:self. view2 animated:YES];
|
I am doing exactly what you have mentioned..... I will try out what u have said and will reply back...... with my code
Thanks for the help
-John M
|
|
|
02-19-2009, 11:49 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Location: India
Posts: 125
|
it works
Hi the solution really worked
here is what i did
in secondViewController.h I declared a string as property
Code:
@interface secondViewController : UIViewController {
IBOutlet UILabel *labelName;
NSString *textValue;
}
@property (nonatomic,retain) UILabel *labelName;
@property (nonatomic,retain) NSString *textValue;
in secondViewController.m
Code:
-(void)viewWillAppear:(BOOL)animated{
labelName.text=textValue;
}
in firstViewController.m
Code:
if(self.secondViewController==nil){
SecondController *view2=[[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.secondViewController=view2;
[view2 release];
}
secondViewController.textValue =txtField.text;
[self.navigationController pushViewController:secondViewController animated:YES];
Thanks for the help
|
|
|
04-15-2009, 05:00 AM
|
#5 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 13
|
Hi Guys,
Really this help me lot..I was struggling to do this same in my application...
Thanks alot...
Asif
|
|
|
04-15-2009, 07:39 AM
|
#6 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 13
|
Hi Friends,
I have another requirement like, am having two views and i have one label in View1 and a button. When button pressed my view navigating to view2, there i have one text field. After entering value in text field am submitting View2 button. This time my view1 label is getting updated (When we do the code in above method). But whenever am submitting view1 button and updating the label, new View1 is creating..ie.View1 not getting updated..
Anyone kow how to do this, please help me..
Thanks,
Asif...
|
|
|
04-22-2009, 12:21 PM
|
#7 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Location: India
Posts: 125
|
Quote:
Originally Posted by asifpv
Hi Friends,
I have another requirement like, am having two views and i have one label in View1 and a button. When button pressed my view navigating to view2, there i have one text field. After entering value in text field am submitting View2 button. This time my view1 label is getting updated (When we do the code in above method). But whenever am submitting view1 button and updating the label, new View1 is creating..ie.View1 not getting updated..
Anyone kow how to do this, please help me..
Thanks,
Asif...
|
Can u post some relevant codes??....
|
|
|
05-11-2009, 10:02 AM
|
#8 (permalink)
|
|
New Member
Join Date: May 2009
Posts: 18
|
Thanks!
Thanks, this is helpful...
I am trying to accomplish something similar, but have started using the Utility Application template and the view is invoked in a different manner. I've noted many have said it is a rather over-complicated template for a simple transition... however, I am quite far through the build process and not sure if I want to start fresh using a different template!
What changes would need to be made to this code to get it working on the Utility Application template?
I have a textField in the flipside view and I would like the text entered to be applied to a label in the main view?
Thank you in advance!
Mark
|
|
|
05-11-2009, 10:48 AM
|
#9 (permalink)
|
|
New Member
Join Date: May 2009
Posts: 18
|
I'm going to try to answer my own question using NSDefaults... my flipside is for settings that will remain largely unchanged... once I have got some working code I'll post it up... I hope it will help others...
|
|
|
05-19-2009, 10:13 AM
|
#10 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Location: India
Posts: 125
|
It is a good idea to use NSUserDefaults.... you can take a look at here App Settings this does almost same thing that you want.
-John
|
|
|
05-19-2009, 11:16 PM
|
#11 (permalink)
|
|
New Member
Join Date: May 2009
Posts: 1
|
Thanks guys!!! this thread really helped me a lot
|
|
|
05-21-2009, 04:49 AM
|
#12 (permalink)
|
|
New Member
Join Date: May 2009
Posts: 18
|
Thanks for posting that John. Yes it did work well for me with passing both floats and strings between screens to update content. Looks like that link has all the example code you would want, so I won't worry about posting mine unless anyone specifically requests?!
Thanks!
|
|
|
05-22-2009, 04:38 PM
|
#13 (permalink)
|
|
New Member
Join Date: May 2009
Posts: 18
|
Talking about NSDefaults... quick question for anyone that knows...
My data that is saved to NSDefaults seems to persist... even following a power cycle... the books I have read talk about several methods for preserving data but NSDefaults is not one of them... I assume there is a good reason for this? Is it not backed up to iTunes for example?  I assume everything should be stored in an archive or array properly...
Thanks in advance for any thoughts
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 532 |
| 39 members and 493 guests |
| !_UK@$, ackpth, atlwx, blex, checkright, CHV, codeflakes, coolman, Cubben2, delphipgmr, designomatt, eimanz, embedded, GeoLogTag, GreenApple, ianian, ihua, iPhoneSpain, Janek2004, JasonR, Johanovski, josechuis, jumbo0, Kroupy, Kryckter, loganbest, lukeca, nathanp, nycos, pjlocko, Saurman, sbuchbin, SmallWonder, Stephane.tamis, striker, x2on, z850, _Mac |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,489
Threads: 35,768
Posts: 156,681
Top Poster: smasher (2,448)
|
| Welcome to our newest member, striker |
|