iPhone实用程序应用程序,从FLipSideView到MainView的连接? [英] iPhone utility application, connection from FLipSideView to MainView?

查看:48
本文介绍了iPhone实用程序应用程序,从FLipSideView到MainView的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Objective-C和iPhone编程,但是遇到了问题.我有一个实用程序应用程序,并且MainView上有一个文本,还有一个单击该按钮时会更改文本的按钮.简单,并且运行良好.但是,如果我不想将按钮放在FlipSideView的背面"上,而仍然使它在正面(MainView)上更改文本,该怎么办?我如何获得意见并进行讨论?我尝试了很多不同的方法,并搜索了answear,但似乎无法弄清楚.

I'm trying to learn Objective-C and iPhone programming, but I'm stuck with a problem. I have a utility application, and I have a text on my MainView and a button that change the text when I click it. Easy, and workes great. But what if I wan't to place the button on the "backside" in the FlipSideView, and still make it change the text on the frontside (MainView)? How do I get the views to talk together? I have tried a lot of different things, and searched for an answear, but can't seem to figure it out.

如果某人有answear,或者链接到教程/示例,那将很棒.

Would be great if someone had a answear, or maybe a link to a tutorial/example.

推荐答案

我想您已经使用了在 MainViewController 中实现以下方法的模板:

I suppose you've used the template which implements the following method in the MainViewController:

- (IBAction)showInfo:(id)sender {    

    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;
...
}

如您所见,它将FlipSideController的委托设置为MainViewController的实例.

As you can see it sets the delegate of the FlipSideController to the instance of the MainViewController.

一种方法是将一个操作放入您的 FlipSideViewController 中,如下所示:

A way would be to put an action into your FlipSideViewController, something like this:

- (IBAction)changeTextInMainView
{
    [(MainViewController *)self.delegate changeText];
}

按下背面的按钮时触发的

.您必须将其连接到IB并将方法添加到标题中.

which is triggered when touching your button on the backside. You've got to wire it in IB as well as add the method to the header.

然后在 MainViewController

- (void)changeText
{
    self.myLabel.text = @"text changed to this";
}

也将此方法添加到标题中.

Add this method to the header as well.

另一种更优雅的方法是将标签的文本保存在一个属性中(可能在其自己的模型类中),该属性可以通过将其向下传递给控制器​​来从任何视图访问.然后将每个viewController的键值观察器添加到属性中,该属性应显示文本并更新视图.

Another more elegant approach would be to save the text of your label in a property(maybe in it's own model class) which can be accessed from any view, by passing it by reference down the controllers. Then add a Key Value Observer from each viewController to the property which should show the text and update the view.

这篇关于iPhone实用程序应用程序,从FLipSideView到MainView的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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