2017-12-04 13 views
0

.textプロパティを別のviewControllerクラスに設定しようとしていますが、設定されません。どのように私はsegueを使用せずにこの結果を達成することができますか?それはinstantiateViewControllerWithIdentifier後にすべてのUI要素が初期化されている必要はありませんAccountTypeVCpresentViewControllerメソッドを使用して別のVCのプロパティを設定する

@property (strong, nonatomic) IBOutlet UILabel *serviceTitle;

答えて

4

AccountTypeVC *vc = (AccountTypeVC *)[mainStoryboard instantiateViewControllerWithIdentifier:@"AccountTypeVC"]; 
AccountTypeVC.serviceTitle.text = [tableData objectAtIndex:indexPath.row]; 
[self presentViewController:vc animated:NO completion:nil]; 

.h。ビューコントローラのviewDidLoadが呼び出されると、すべてのUI要素をデータでバインドすることをお勧めします。

AccountTypeVCに別のプロパティを追加します。

@property (strong, nonatomic) NSString *serviceTitleText; 

viewDidLoadの方法でラベル付けします。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.serviceTitle.text = self. serviceTitleText; 
} 

そしてAccountTypeVCを提示する前に、代わりにラベルのserviceTitleTextプロパティを設定します。

AccountTypeVC *vc = (AccountTypeVC *)[mainStoryboard instantiateViewControllerWithIdentifier:@"AccountTypeVC"]; 
vc.serviceTitleText = [tableData objectAtIndex:indexPath.row]; 
[self presentViewController:vc animated:NO completion:nil]; 
+0

ここでNSStringをNSMutableArrayに変更しましたが、それはなぜ機能しませんか? – AsimRazaKhan

関連する問題