Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone ($4.99)

dotnetIQ ($4.99)

Your First iPhone App ($1.99)

iPocket Tools 9 in 1 ($0.99)

Catch-Me (Free)

Alien Strike ($0.99)

Historic Olympic Medal-Table ($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

Reply
 
LinkBack Thread Tools Display Modes
Old 02-17-2009, 08:31 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 125
Default 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
JohnMabassa is offline   Reply With Quote
Old 02-18-2009, 04:42 PM   #2 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 8
Thumbs up

Quote:
Originally Posted by JohnMabassa View Post
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];
markwilliams is offline   Reply With Quote
Old 02-19-2009, 11:14 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 125
Default

Quote:
Originally Posted by markwilliams View Post
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
JohnMabassa is offline   Reply With Quote
Old 02-19-2009, 11:49 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 125
Default 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
JohnMabassa is offline   Reply With Quote
Old 04-15-2009, 05:00 AM   #5 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 13
Smile

Hi Guys,


Really this help me lot..I was struggling to do this same in my application...


Thanks alot...

Asif
asifpv is offline   Reply With Quote
Old 04-15-2009, 07:39 AM   #6 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 13
Default

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...
asifpv is offline   Reply With Quote
Old 04-22-2009, 12:21 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 125
Default

Quote:
Originally Posted by asifpv View Post
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??....
JohnMabassa is offline   Reply With Quote
Old 05-11-2009, 10:02 AM   #8 (permalink)
New Member
 
Join Date: May 2009
Posts: 18
Default 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
mplaczek is offline   Reply With Quote
Old 05-11-2009, 10:48 AM   #9 (permalink)
New Member
 
Join Date: May 2009
Posts: 18
Default

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...
mplaczek is offline   Reply With Quote
Old 05-19-2009, 10:13 AM   #10 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 125
Default

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
JohnMabassa is offline   Reply With Quote
Old 05-19-2009, 11:16 PM   #11 (permalink)
New Member
 
Join Date: May 2009
Posts: 1
Default

Thanks guys!!! this thread really helped me a lot
roaringtiger is offline   Reply With Quote
Old 05-21-2009, 04:49 AM   #12 (permalink)
New Member
 
Join Date: May 2009
Posts: 18
Default

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!
mplaczek is offline   Reply With Quote
Old 05-22-2009, 04:38 PM   #13 (permalink)
New Member
 
Join Date: May 2009
Posts: 18
Default

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
mplaczek is offline   Reply With Quote
Reply

Bookmarks

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
» Stats
Members: 21,489
Threads: 35,768
Posts: 156,681
Top Poster: smasher (2,448)
Welcome to our newest member, striker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0