我通常使用委托协议:
在第二个视图中添加:
@protocol viewControllerDelegate;
@interface viewController : UIView
id < viewControllerDelegate > delegate;
@property (nonatomic, assign) id < QuickViewControllerDelegate > delegate;
@end
@protocol viewControllerDelegate
- (void)viewController:(ViewController *)controller stringForLabel:(NSString*)string;
@end
Run Code Online (Sandbox Code Playgroud)
在第二个视图m文件调用:
[delegate quickViewController:self
stringForLabel:@"your string"];
Run Code Online (Sandbox Code Playgroud)
在主视图中h文件添加:,像那样:
@interface MainView:UIViewController<viewControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
在主视图m文件中:
第一:当你初始化第二个视图时别忘了添加:
secondview.delegate = self;
Run Code Online (Sandbox Code Playgroud)
另外,它不会工作.
第二:添加委托功能:
- (void)viewController:(ViewController*)controller stringForLabel:(NSString*)string{
//set the label from the string passed
lable.text = string;
}
Run Code Online (Sandbox Code Playgroud)
希望它能帮助shani
| 归档时间: |
|
| 查看次数: |
803 次 |
| 最近记录: |