如何从第 2 个 viewcontroller 获取 tableview 单元格文本标签到第一个 viewcontroller 的标签?

How to get tableview cell text label from 2nd viewcontroller to a label from 1st viewcontroller?

我是新 iOS 开发人员。 我有 2 viewcontroller 就像下面的 2 张图片(我将其称为 VC1 和 VC2):
VC1:

而 VC2 是打印机列表:

现在我希望每次在 VC2 中选择一个单元格然后按右上角的右栏按钮时,单元格的文本标签将发送到 VC1 并显示而不是 EP-806A 标签,我在互联网上搜索并找到解决方案是写一个委托来传递数据。但我不知道如何在我的案例中写它。有人可以帮帮我吗?

1st 在 VC2 中,必须创建委托

@protocol VC2Delegate;
@interface VC2 : UIViewController
@property (nonatomic, weak) id <VC2Delegate> delegate;
@end

@protocol VC2Delegate <NSObject>
@required
- (void)changeToText:(NSString *)text;
@end

@implementation VC2
// this is your "完了" action
- (IBAction)doneAction:(id)sender {
   ...
   [self.delegate changeToText:@"what you want"];
}
@end

2、将delegate添加到VC1

@interface VC1 : UIViewController <VC2Delegate>
@end

3、记得设置VC2.delegate为VC1

VC2 *vc2 = [VC2 new];
vc2.delegate = self;
[self.navigationController pushViewController:vc2 animated:YES];

4、在VC1

中实现changeToText:
@implementation VC1
- (void)changeToText:(NSString *)text {
    // change the text here
}
@end

希望对您有所帮助。