如何从CCScrollView上的按钮更改标签文本? [英] How to change labels text from a button on a CCScrollView?

查看:181
本文介绍了如何从CCScrollView上的按钮更改标签文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前发布过类似的东西,但我认为这篇文章很混乱,所以我重做了。

I posted something very similar earlier, but I think the post was confusing so I'm redoing it.

这里是设置。我使用SpriteBuilder。我有2个CCB类,MainScene.ccb和Scroll.ccb。 Scroll.ccb是一个带有按钮的图层。 MainScene包含一个CCScrollView和一个CCLabelTTF。 CCScrollView正在加载Scroll.ccb。 CCScrollView占用了MainScene接口的一半,另一半是一个带有标签的CCColor。

Here's the setup. I am using SpriteBuilder. I have 2 CCB classes, MainScene.ccb and Scroll.ccb. The Scroll.ccb is a layer with a button on it. MainScene contains a CCScrollView and a CCLabelTTF. The CCScrollView is loading Scroll.ccb. The CCScrollView takes up half of the interface of MainScene, and on the other half is a CCColor that has the label on it.

当我点击CCScrollView的按钮时,我想要MainScene上的标签更改其文本。我遇到的问题是标签文本不会改变。但是如果我写一个NSLog内部的buttons方法来输出日志中的文本,那么DOES的工作。

When I click the button on the CCScrollView, I want the label on MainScene to change its text. The problem I am having is that the labels text doesn't change. However if I write an NSLog inside the buttons method to output text in the log, that DOES work.

我包括四张图片,以帮助你更好地了解情况。
http://imgur.com/a/77XyJ

I am including four pictures to help you better understand the situation. http://imgur.com/a/77XyJ

我已经在我的主项目上停留了一个多星期。我真的不知道该怎么办,我已经尝试了一堆没有工作的东西,我已经用完了想法。

I've been stuck on this for over a week now on my main project. I honestly have no clue what to do anymore, I've tried a bunch of things that didn't work, and I've run out of ideas.

编辑:好吧,所以我有一点,但进一步调试这个问题。我插入一个标签到scrollview,并命名为Label2。在按钮方法下,我添加了Label2.string = @Test',当我运行程序并单击按钮时,scrollview上的标签改变了。所以看起来当按钮被点击时,它在MainScene中查找方法并找到它,但它不能更新不同CCNode上的标签。

Okay so I got a little but further in debugging the issue. I inserted a label into the scrollview, and named it Label2. Under the buttons method I added 'Label2.string = @"Test"' and when I ran the program and clicked the button, the label on the scrollview changed. So it seems that when the button is being clicked, it looks in MainScene for the method and finds it, but it can't update a label on a different CCNode.

推荐答案

您是否已将此方法链接到点击我按钮?或者尝试创建IBAction?

Do you have linked this method to the "click me" button ? Or maybe try to create a IBAction ?

-(void)testButton {

       changeLabel.String = @"Changed !";
}

- (IBAction)testButton:(id)sender {

    changeLabel.String = @"Changed !";

}

我的意思是在你的故事板和拖放)

i mean in your storyboard ( create the link with ctrl key and drag drop )

希望这将有助于你。

这篇关于如何从CCScrollView上的按钮更改标签文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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