从另一个视图更改标签

awl*_*lcs 1 iphone

我的主视图上有一个标签.我有一个按钮,可以将我带到另一个视图.在它上面我有一个按钮来更改主视图上的标签.

我怎样才能做到这一点?我加了一个项目,请有人帮帮我...

项目:这里

sha*_*oga 5

我通常使用委托协议:

在第二个视图中添加:

@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