views:

1031

answers:

5

hi i am new to objective c. i have a login view controller with .h, .m, .xib files. and after successful login i need to go to the second page.

The scenario is this, i am accessing web services. to authenticate the user, i send the username and password to the web service and in return i get a string value. based on the results of the string value i need to display a second screen. Please help

+1  A: 

You can create a class to store some shared data and create an instance of it in your application delegate. in such way you can use this shared data in any class of your app.

Morion
can you please provide me the sample code..
shreedevi
+1  A: 

If you only need to pass just a few values you can make them parameters to the init method. For example:

-(id)initWithUserName:(NSString *)name andPassword:(NSString *)password {
    self = [super init];
    if (nil == self) {
        return nil;
    }

    // display or store login info somewhere
    [someLabel setText:name];

    return self
}

Otherwise if you have a lot of values you want to use in the next view go with Morion's advice and make a separate class.

ihuk
By looking at some of the posted code you can extend your SecondView's init method with additional NSString parameter, like in the example above.
ihuk
i still did not get you..i have a first view controller.m, that gets the result value from a web service in a NSMutable String. now i want to display it in Second View
shreedevi
I guess you have [[SecondView alloc] init] somewhere in your code. If yo add another parameter to init method like I described then you can use [[SecondView alloc] initWithSomething:string] to pass value of string to your second view.
ihuk
+1  A: 

OPNe way is to create properties in the app delegate. Each controller can access the appdelegate with:

[[UIApplication sharedApplication] delegate]
zaph
A: 

You can't display values in nib files.

Get a reference to the Standard user defaults and store the string in there. Then you'll have access to the value wherever you want.

bpapa
A: 

Hi,

Is this your questions; when you get your response from the server, you need to make a view controller and put that string into it?

Try something like this in your first view controller

// Get the string from the server
NSString *string = [get string from server];

// Create the second controller
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"nibname" bundle:nil];

// Set the text property of a label in the controller
controller.myLabel.text=string;

// Add the view to the window so we can see it
[[[[UIApplication sharedApplication] delegate] window] addSubview:controller.view];

This will create a new controller, set a string in it and display it in the window.

You will need to make a xib file that contains a UILabel and attach it to a propety called myLabel in the second controller i.e.

@interface SecondViewController {
  UILabel *myLabel;
}

@property (nonatomic, retain) IBOutlet UILabel *myLabel;

@end

Hope this helps,

Sam

deanWombourne
Its not working ...
Rajesh Rolen- DotNet Developer
You might need to provide more information than 'it's not working' otherwise it's tricky to help you :)
deanWombourne