开发者

xcode init controller with data

I would like to pass two strings from current view to userViewController when this one is initialized. Will be possible to init userViewController with, in my case开发者_运维问答, two strings? Sorry if is a basic objective-c issue, I never did it, always use alternative methods as singleton or setter. Thanks for help.

if (self.controladorUser == nil)
    {
        userViewController *aController = [[userViewController alloc] initWithNibName:@"userViewController" bundle:];
        self.controladorUser = aController;
        [aController release];
    }

    [UIView setAnimationTransition: UIViewAnimationOptionCurveEaseIn forView:self.view cache:YES];   
    [self.controladorPass viewWillDisappear:YES];
    [self.controladorUser viewWillAppear:YES];

    [self.controladorPass.view removeFromSuperview];
    [self.view insertSubview:controladorUser.view   atIndex:0];

    [self.controladorPass viewDidDisappear:YES];
    [self.controladorUser viewDidAppear:YES];

    [UIView commitAnimations];

in userViewController something like: (id)initWithData:


It would be a good idea to create your own init method for the view controller you want to create them with. For example:

-(id)initWithNibName:(NSString *)nibName bundle(NSBundle *)nibBundle stringOne:(NSString *)aStringOne stringTwo(NSString*)aStringTwo
{
    self = [super initWithNameName:nibName bundle:nibBundle];
    if (self)
    {
        [self setStringOne:aStringOne];
        [self setStringTwo:aStringTwo];
    }
    return self;
}

Hope this helps :)


Or make the two strings properties (nonatomic, copy) and set them immediately after you do the alloc/init.


Just make a custom initializer with your 2 strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜