2013-11-27 43 views
-1

我剛開始使用iOS,並試圖瞭解委託人如何傳遞數據。 我明白如何將數據從ControllerA傳遞到ControllerB。將數據從ControllerA傳遞給控制器​​B,然後傳遞給ControllerC

現在將數據從ControllerA傳遞到控制器B然後傳遞給ControllerC的最佳方法是什麼?數據將完全相同。

我花了3,4個小時,無法得到解決方案。我環顧四周,沒有找到足夠的隊形。到樣品的鏈接也將是非常有益的

+0

B和C之間正在做什麼?像從A到B一樣推送或呈現視圖? –

+0

作爲參考,你可以看到這個http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – wasim

+0

好吧,我不認爲我已經理解了這個問題......但控制器可以只是有一個屬性定義...你可以發佈一些代碼,這樣我可以更好地理解你的問題? – Deboroh88

回答

-1

首先,你必須在B級後,你可以訪問這樣的字符串傳遞值使用此代碼來創建的NSString:

- (IBAction) nextClass:(id) sender 
{ 
ClassB *b = [[ClassB alloc] initWithNibName:@"ClassB" bundle:nil]; 

b.stringb = [NSString stringWithFormat:@"%@", put your string/array here to pass the value to next view controller]; 

[self.navigationController pushViewController:b animated:YES]; 

} 
-1

首先你必須在A類中創建一個對象並且在B類中創建相同對象之後,您可以像這樣訪問對象以傳遞值使用此代碼:

#pragma mark prepareForSegue 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

    if ([segue.identifier isEqualToString:@"classA"]) 
     { 
     UITabBarController *tab = [segue destinationViewController]; 
     classA *a= [[ClassView alloc] init]; 
     a = (ClassView *)[[tab customizableViewControllers]objectAtIndex:0]; 
     a.object = object; 

    }if ([segue.identifier isEqualToString:@"classB"]) 
     { 
      UITabBarController *tab = [segue destinationViewController]; 
      classB *b= [[ClassView alloc] init]; 
      b = (ClassView *)[[tab customizableViewControllers]objectAtIndex:0]; 
      b.object = object; 
    }if ([segue.identifier isEqualToString:@"classC"]) 
      { 
      UITabBarController *tab = [segue destinationViewController]; 
      classC *c= [[ClassView alloc] init]; 
      c = (ClassView *)[[tab customizableViewControllers]objectAtIndex:0]; 
      c.object = object; 
     } 
} 
+0

不包括從B到C的傳球 – Abizern

相關問題