首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS:将值从UITableView行传递到第一个控制器中的UILabel

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

Stack Overflow用户
提问于 2013-05-07 23:47:46
回答 1查看 271关注 0票数 0

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

我想用文本选项更新UILabel。

我已经在第一个控制器上添加了一个UILabel并连接到了H.file,但我不知道如何继续

代码语言:javascript
复制
 I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings. 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-08 00:08:33

为此,您应该使用委托。

SecudViewController.h:

代码语言:javascript
复制
@protocol SecondViewControllerDelegate;

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

@protocol SecondViewControllerDelegate <NSObject>
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text;
@end

SecudViewController.m:

代码语言:javascript
复制
@implementation
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self.delegate secondViewController:self didTapRowWithText:cell.yourLabel.text];
}
...
@end

无论是谁创建并推动了SecondViewController (也许/希望也是第一个):

代码语言:javascript
复制
// put this after secondViewController initialization
secondViewController.delegate = self;

- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text
{
    firstViewController.yourLabel.text = text;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16423325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档