2011-07-03 22 views
0

我有一个对象名称usr。我想改变看法,我想将它传递给新视图。我怎样才能传递这个对象?这样做的将对象传递给不同的视图

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

回答

1

一种方法是在exampleClass声明RVUser类型的属性,它创造exampleController后分配到该属性。

0

您应该设置属性使用[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]; 
+0

好点,但它没有解决他的问题 – RyanR

0

你要申报ExampleController的实例作为您的自定义的UIViewController,而不是之前的UIViewController - 这会给你的代码完成和编译时警告,如果调用方法/属性不会退出。然后,改变你的ExampleClass中的定义(读的命名惯例指南还)有型RVUser的属性,像这样:

@property (nonatomic, retain) RVUser *user; 

而且在实现文件:

@synthesize user; 

现在,你可以通过你的对象到控制器,你显示前:

ExampleController.user = usr; 

你真的应该阅读有关苹果开发者网站的介绍指南,它们涵盖这和更多,你需要知道,如果你想写iOS应用程序。

相关问题