1.屬性傳值
屬相傳值一般從前向後,即從A到B,要傳什麼類型值,就在B頁面定義什麼樣的屬性
如要將一個字符串從A傳到B,就在B頁面設置以下屬相
@property(nonatomic,retain)
NSString *str ;//接受的值
在A控制器跳轉方法內實現
-
(void)showSecondView:(UIButton*)btn
{SecondViewController
*VC = [[SecondViewController alloc] init
];
VC.str =@"我是屬性傳值"
;
[self
presentViewController:VC animated:YES completion:nil];
}
2.delegate
在頁面B設置協議及方法
//設置代理
@protocol
secondViewDelegate
//代理方法
(爲防止循環引用用weak修飾)-(
void
)showMessage:(NSString
*)messageStr;
@end
//SecondViewController.h
@interface
SecondViewController
: UIViewController
@property
(nonatomic,
weak)id<secondViewDelegate> delegate;
@end
//SecondViewController.m
-
(void)backFirst:(UIButton*)btn{
[self.delegate showMessage:@"我是代理傳值"];
[self
dismissViewControllerAnimated:YES completion:nil];
}
-(
void
)showName:(NSString
*)messageStr{
NSLong(@"%@",messageStr);
}