viewcontroller를 푸시 할 때 어떻게 데이터를 길게 전달합니까 (예 : "asdf": 123)? NSBundle에 객체를 추가해야합니까?iOS - 푸시 된 viewcontroller에 데이터 전달
6
A
답변
16
MyViewController * myVC = [[MyViewController alloc] initWithNibName:nil bundle:nil];
myVC.someProperty = someValue; // Pass your data here
[self.navigationController pushViewController:myVC animated:YES];
그리고 :
.H
@interface MyViewController : UIViewController
@property (nonatomic, strong) NSString * someProperty;
@end
하는 .m
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// your data has been set
// self.someProperty is equal to "some value"
}
1
믿을 수는 없지만 물론 관련 속성이나 메서드를 ViewController 클래스에 추가하고이를 푸시하기 전에 사용할 수 있습니다.
+1
내가 쓴 것은 정확히 수용된 대답이 코드에서하는 것과 같은 것입니다. – Clafou
0
아니요. NSBundle
을 Android의 Bundle
과 동일시 할 수 있지만 관련이 없으며 유사한 작업을 수행하지 않습니다. Clafou는 메서드와 속성을 통해 데이터를 전달할 것을 제안하는 것이 옳습니다. 당신의 MyViewController
클래스
또는 당신이 무엇을해야합니까? – KaiserJohaan