带数据的xcode init控制器

时间:2011-10-16 21:16:43

标签: objective-c ios xcode cocoa-touch uiviewcontroller

我想在初始化这个字符串时将两个字符串从当前视图传递给userViewController。有可能在我的情况下,用initView userController两个字符串吗?对不起,如果是一个基本的Objective-c问题,我从来没有这样做,总是使用替代方法作为singleton或setter。谢谢你的帮助。

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:

3 个答案:

答案 0 :(得分:3)

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

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

希望这会有所帮助:)

答案 1 :(得分:1)

或者进行两个字符串属性(非原子,复制)并在执行alloc / init后立即设置它们。

答案 2 :(得分:0)

只需使用2个字符串制作自定义初始化程序。