How to change labels text from a button on a CCScrollView?(如何从 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,上面有label.
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 以在日志中输出文本,那确实可以工作.
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.
好的,所以我在调试问题方面得到了一点但更进一步.我在滚动视图中插入了一个标签,并将其命名为 Label2.在按钮方法下,我添加了'Label2.string = @Test"',当我运行程序并单击按钮时,滚动视图上的标签发生了变化.所以看起来当按钮被点击时,它在 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 !";
}
我的意思是在你的故事板中(使用 ctrl 键创建链接并拖放)
i mean in your storyboard ( create the link with ctrl key and drag drop )
希望这会对你有所帮助.
Hope this will help you.
这篇关于如何从 CCScrollView 上的按钮更改标签文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 CCScrollView 上的按钮更改标签文本?
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01