在我的第二个控制器中,当用户选择一行并单击后退按钮
我想用文本选择更新UILabel。
我在第一个控制器上添加了一个UILabel并连接到了h。文件,但我不知道如何继续
I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings.
答案 0 :(得分:0)
您应该使用委托。
SecondViewController.h:
@protocol SecondViewControllerDelegate;
@interface
...
@property (nonatomic, assign) id <SecondViewControllerDelegate> delegate;
...
@end
@protocol SecondViewControllerDelegate <NSObject>
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text;
@end
SecondViewController.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;
}