IOS:将值从UITableView行传递到第一个控制器中的UILabel

IOS:将值从UITableView行传递到第一个控制器中的UILabel,ios,uitableview,static,uilabel,Ios,Uitableview,Static,Uilabel,在我的第二个控制器中,当用户选择一行并单击后退按钮后 我想用文本选项更新UILabel 我在第一个控制器上添加了UILabel并连接到h。但我不知道怎么回事 I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings. 您应该为此使用代理 SecondViewController.h: @protocol SecondViewControllerDelegate; @interface

在我的第二个控制器中,当用户选择一行并单击后退按钮后

我想用文本选项更新UILabel

我在第一个控制器上添加了UILabel并连接到h。但我不知道怎么回事

 I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings. 

您应该为此使用代理

SecondViewController.h:

@protocol SecondViewControllerDelegate;

@interface
...
@property (nonatomic, assign) id <SecondViewControllerDelegate> delegate;
...
@end

@protocol SecondViewControllerDelegate <NSObject>
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text;
@end
创建并推送第二个ViewController(可能/希望也是第一个)的人:


FirstController的最后一部分我有一些疑问…我必须实现PrepareForSegue…现在我在Storyboard中使用连接我不知道您正在使用Storyboard。。但据我所知,通常您可以为控制器设置情节提要id,并通过代码中的此id访问控制器。谢谢。在故事板中添加了一个推送SEGUE的ID后,一切正常,欢迎!我真的很感激,如果你能接受这个答案并给我投赞成票,那就太好了:-)
@implementation
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self.delegate secondViewController:self didTapRowWithText:cell.yourLabel.text];
}
...
@end
// put this after secondViewController initialization
secondViewController.delegate = self;

- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text
{
    firstViewController.yourLabel.text = text;
}