在我的第二个控制器中,当用户选择一行并单击back按钮后
我想用文本选项更新UILabel。
我已经在第一个控制器上添加了一个UILabel并连接到了H.file,但我不知道如何继续
I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings. 发布于 2013-05-08 00:08:33
为此,您应该使用委托。
SecudViewController.h:
@protocol SecondViewControllerDelegate;
@interface
...
@property (nonatomic, assign) id <SecondViewControllerDelegate> delegate;
...
@end
@protocol SecondViewControllerDelegate <NSObject>
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text;
@endSecudViewController.m:
@implementation
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[self.delegate secondViewController:self didTapRowWithText:cell.yourLabel.text];
}
...
@end无论是谁创建并推动了SecondViewController (也许/希望也是第一个):
// put this after secondViewController initialization
secondViewController.delegate = self;
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text
{
firstViewController.yourLabel.text = text;
}https://stackoverflow.com/questions/16423325
复制相似问题