2011-07-03 23 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應用程序。

相關問題