2

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
  • i tried creting a new shared class. it creates 2 files for me shared.h, and shared.m Now i place my string value in shared.h file and save the file. the shared.h file has NSMutableString *soapresult; now in the my login view controller it looks like. @class SecondView #import<UIKit/UIKit.h> @inteface LoginView : UIViewController { // username textfield; //password //login button Shared *sharedObject; } now in login view.m file i try to use the string as sharedObject.soapResults. But i get error. Please help Commented Nov 6, 2009 at 8:04

6 Answers 6

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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
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.
1

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.

Comments

1

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

[[UIApplication sharedApplication] delegate]

Comments

1

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

1 Comment

You might need to provide more information than 'it's not working' otherwise it's tricky to help you :)
0

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.

Comments

0
NSString *str1 = @"Apple";
NSString *str2 = @"Orange";

if([str1 isEqualToString: str2]) {

}else{

}

it will help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.