IAddBugsToCodebases
IAddBugsToCodebases

Reputation: 525

Passing objects to a different view

I have an object name usr. I want to change views and I want to pass it along to the new view. How can I pass this object?

RVUser *usr = [[RVUser alloc] init];

UIViewController* exampleController = [[exampleClass alloc] initWithNibName:@"RVListsController" bundle:nil];
if (exampleController) {
    exampleController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:exampleController animated:YES];
        if (exampleController.title == nil) {
            NSLog(@"enters");
            //exampleController.title = @"Revistas Destacadas";
        }
        [exampleController release];
    }   
}

Upvotes: 0

Views: 122

Answers (3)

RyanR
RyanR

Reputation: 7758

You'll want to declare the instance of ExampleController as your custom UIViewController instead of UIViewController - this will give you code completion and compile time warnings if you call a method/property on it that doesn't exit. Then, change your definition of exampleClass (read the naming convention guide also) to have a property of type RVUser, like so:

@property (nonatomic, retain) RVUser *user;

And in the implementation file:

@synthesize user;

Now you can pass your object to that controller before you display it:

ExampleController.user = usr;

You really should read the intro guides on the Apple developer site, they cover this and a lot more that you need to know if you want to write iOS apps.

Upvotes: 0

petershine
petershine

Reputation: 3200

You should set properties BEFORE using [self presentModalViewController:exampleController animated:YES];

RVUser *usr = [[RVUser alloc] init];

UIViewController* exampleController = [[exampleClass alloc] initWithNibName:@"RVListsController" bundle:nil];

if (exampleController) {
    exampleController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    if (exampleController.title == nil) {
        NSLog(@"enters");
        //exampleController.title = @"Revistas Destacadas";
    }

    //TODO: Set exampleController properties, declared as @property (nonatomic, release) RVUser *passedUsr;
    //exampleController.passedUsr = usr;
    //[usr release];

    [self presentModalViewController:exampleController animated:YES];
}

[exampleController release];

Upvotes: 0

Jim
Jim

Reputation: 73966

One way of doing it is to declare a property of type RVUser on exampleClass and assign it to that property after creating exampleController.

Upvotes: 1

Related Questions