Reputation: 3
(iPhone Development Xcode 4.3)
Ive got a textfield on a view controller and an NSString on another controller. What I'm trying to do is to allow the user to enter a URL in the textfield and pass that as the path in my other controller.
This is the NSString I'm currently using:
NSString * path = @"http://www.test.com";
So im looking to do something like:
NSString * path = INPUT FROM USER;
Hope someone can point me in the right direction.
Upvotes: 0
Views: 623
Reputation: 1484
Basically you will need two things:
As you've already known, all you need to do is to set your IBOutlet on your textfield and read the string.
You have two options to do it:
First, you can add a string to your second view controller and set it property. Then create a custom -init to receive the url string. In your first view controller, when you create the second view controller(I assume that's the case), use your custom -init to set the value.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andURL:(NSString *) url
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.urlString = url;
}
return self;
}
You have another option: create a method on the second view controller.
so in your second view controller, do this:
-(void) setURL: (NSString *) url
{
self.rulString = url;
}
and in your first view controller, do:
SecondViewController *secondVC = [SecondViewController alloc] init];
// get url string from user input and store it in a local string variable named tempURL
[secondVC setURL:tempURL];
Hope this helps.
Upvotes: 0
Reputation: 2218
NSString *urlString = [NSURL URLWithString:textfield.text];
Upvotes: 0
Reputation: 5267
use
NSString *path = textField.text;
for that create IBOutlate for that textField
Upvotes: 1