IBOutlet不在UI中显示其值 [英] IBOutlet does not display its value in UI

查看:86
本文介绍了IBOutlet不在UI中显示其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用情节提要构建iOS应用.我已经在我的应用中使用swift实现了Google地图,其余代码在目标C中.

I am building an iOS app using storyboards.I have implemented google maps in my app using swift and rest of the code is in objective C.

我的情况:

1.如图所示,当我单击位置前面的标签(在第一视图控制器"中)时,模式搜索会打开包含地图的第二个视图控制器.

1.As shown in the diagram, when I click on the label in front of location ( in First view controller ) a modal segue opens a second view controller containing map.

2.在地图视图控制器中,当用户触摸移动地图时,我会在标签中获取地址值. (类似于uber应用)

2.In the map view controllers, when the user moves the map with touch, I'm getting address value in a label. ( similar to uber app )

3.此后,一旦用户按下此控制器上的完成按钮,它就会使用自定义segue和位置值返回到第一个视图控制器.

3.After this , as soon as user presses done button on this controller, it gets back to the first view controller using custom segue and with the value of the location.

问题在于,此标签的iboulet隐藏在用户界面中,并且不显示其值.但是,当我在控制台中打印此值时,我可以显示该值.

The problem is that, iboulet of this label is hidden in the UI and doesn’t display its value. But when I print this value in console, I am able to display the value.

下面是我的代码.非常感谢您的帮助.

Below is my code. Help is much appreciated.

快速编写的First View Controller代码:

First View Controller code written in swift:

- (void)viewDidLoad {
    [super viewDidLoad];
    _Locationlabel.text=_location;
    NSLog(@"location=%@",_Locationlabel.text);
}

第二个View Controller代码:

Second View Controller code:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if (segue.identifier == "locationDone") {
            // pass data to next view

            var svc = segue.destinationViewController as Host;

            svc.location = self.addressLabel.text;
            println("location\(svc.location)");
        }
    }

    @IBAction func doTap(x:UIButton) {

     self.dismissViewControllerAnimated(true, completion: {});//This is intended to dismiss the Info sceen.
        println("pressed")

    }

推荐答案

您不应使用自定义键来返回到您的第一个视图控制器. Segues总是创建视图控制器的新实例(除非您使用展开式Segue).在您的第一个视图控制器中,添加以下方法:

You shouldn't use a custom segue to return to your first view controller. Segues always create a new instance of a view controller (unless you use an unwind segue). In your first view controller, add this method:

- (IBAction)backFromMapView:(UIStoryboardSegue *)segue
{
    NSLog(@"and we are back");
    MapViewController* mvc = (MapViewController *)segue.sourceViewController;
    NSLog(@"location %@", mvc.addressLabel.text);
}

别忘了#import <YourProjectName>-Swift.h,这样Host.m就会知道MapViewController.

Don't forget to #import <YourProjectName>-Swift.h so that Host.m will know about MapViewController.

然后,您需要控制从Map View Controller中的Done按钮拖动到Storyboard中View Controller上方栏中的橙色退出图标.在弹出窗口中,选择backFromMapView,然后完成.

Then you'd control drag from the Done button in your Map View Controller to the orange exit icon in the bar above the view controller in the Storyboard. In the pop up, you'd select backFromMapView and voila, you're done.

这篇关于IBOutlet不在UI中显示其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆