如何将值传递给另一个视图控制器?

时间:2011-11-29 09:18:31

标签: iphone

我想通过这种方式将localstringtextnote传递给Uploadviewcontroller,

UIViewController *controllerNew = [[UploadViewController alloc] initWithNibName:@"UploadView" bundle:nil owner:self];
        controllerNew.localStringtextnote = localStringtextnote;
        [self.navigationController pushViewController:controllerNew animated:YES];
        [controllerNew release];

但我收到此错误“@property localstringtextnote不喜欢uiviewcontroller类型的对象” 要么 我想通过modalTransistionstyle

UploadViewController *aSecondViewController = [[UploadViewController alloc] initWithNibName:@"UploadView" bundle:nil];
        aSecondViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:aSecondViewController animated:YES];


        [UIView commitAnimations];

怎么做?提前谢谢。

4 个答案:

答案 0 :(得分:2)

声明变量

NSString *_localStringtextnote;

UploadViewController.h档案中。

还在同一文件中为该变量添加属性。

@property(nonatomic,copy) NSString *localStringtextnote;

在.m文件中,在实现中合成它。

@synthesize localStringtextnote=_localStringtextnote;

现在运行应用程序。

答案 1 :(得分:1)

        UploadViewController *controllerNew = [[UploadViewController alloc] initWithNibName:@"UploadView" bundle:nil owner:self];
        controllerNew.localStringtextnote = localStringtextnote;
        [self.navigationController pushViewController:controllerNew animated:YES];
        [controllerNew release];

将uiview控制器更改为UploadViewController,因为uiview控制器没有任何属性localStringtextnote

答案 2 :(得分:0)

您必须在localStringtextnote中将UploadViewController声明为@property(nonatomic,retain)NSString * localStringtextnote;,并在.m文件中进行综合。

答案 3 :(得分:-1)

在controllerNew中创建一个新方法(不要忘记在* .h文件中声明它):

-(id) setParams:(NSString*)str {
   localStringtextnote = [[NSString alloc] initWithString:str];
   return self;
}

然后,当你需要puth这个视图控制器时:

    UploadViewController *controllerNew = [[UploadViewController alloc] initWithNibName:@"UploadView" bundle:nil owner:self];
        [self.navigationController pushViewController:controllerNew animated:YES];
controllerNew = [controllerNew setParams:localStringtextnote];
    [controllerNew release];