本文介绍了带有数据的xcode初始化控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初始化后,我想将两个字符串从当前视图传递给userViewController。以我为例,可以用两个字符串初始化userViewController吗?抱歉,如果这是一个基本的Objective-C问题,我从来没有做过,请始终使用替代方法作为singleton或setter。

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];

在userViewController中类似:(id)initWithData:

in userViewController something like: (id)initWithData:

推荐答案

为要用来创建视图控制器的视图控制器创建自己的init方法是一个好主意。例如:

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;
}

希望这会有所帮助:)

这篇关于带有数据的xcode初始化控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:46
查看更多