关闭模式视图时更新 UILabels
Posted
技术标签:
【中文标题】关闭模式视图时更新 UILabels【英文标题】:Update UILabels when dismissing a modal view 【发布时间】:2015-01-11 16:04:54 【问题描述】:当我想在关闭模式后更新 UILabels 时遇到问题。 基本上我有: 带有一些 UILabel 和 UIButtons 的 ViewController 当我触摸一个按钮时,它会打开一个带有文本字段的模式,我在该文本字段中键入一些文本,该文本将保存到我所做的 CacheHandler 的实例中。 然后我用一个按钮关闭我的模式,我想看看我在 UILabel 中输入的文本。 文本保存在缓存中,我已经检查过了。当我从自定义 segue 调用它时,我有一种更新标签的方法,标签值为空。我哪里做错了?
自定义转场:
#import "DismissModalSegue.h"
#import "CreateSqeedViewController.h"
@implementation DismissModalSegue
- (void)perform
UIViewController *sourceViewController = self.sourceViewController;
CreateSqeedViewController *destViewController = self.destinationViewController;
[sourceViewController.presentingViewController dismissViewControllerAnimated:YES completion:^
[destViewController updateLabels];
];
@end
updateLabels 方法:
- (void)updateLabels
NSLog(@"Updating labels: %@", [[[CacheHandler instance] createSqeed] place]);
/* displays what I want to display in my label */
NSLog(@"%@", whatLabel.text);
/* displays null */
whereLabel.text = [[[CacheHandler instance] createSqeed] place];
whatLabel.text = [[[CacheHandler instance] createSqeed] sqeedDescription];
NSString *peopleLabel = [NSString stringWithFormat:@"%@ / %@", [[[CacheHandler instance] createSqeed] peopleMin], [[[CacheHandler instance] createSqeed] peopleMax]];
whoLabel.text = peopleLabel;
whereLabel.text = [[[[CacheHandler instance] createSqeed] dateStart] description];
【问题讨论】:
为什么不使用在 VC 上调用方法的 unwind segue?并且不需要自定义 segue。 【参考方案1】:初始化标签在哪里?是否与 IBOutlet 连接? 可能在它们未初始化时回调它们
【讨论】:
它们是 .h 中的 IBOutlet 属性并在 .m 中合成。我检查了 viewDidLoad 方法,它们被完美地初始化了,它们有一个默认值。 updateLabels 方法调用是否正确?您可以尝试使用 NSNotificationCenter 发送通知以调用该方法。 看这里[链接]***.com/questions/27874673/…以上是关于关闭模式视图时更新 UILabels的主要内容,如果未能解决你的问题,请参考以下文章