How to change labels text from a button on a CCScrollView?

蓝咒 提交于 2019-12-31 04:59:07

问题


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

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.

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.

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.

EDIT: 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.


回答1:


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

-(void)testButton {

       changeLabel.String = @"Changed !";
}

OR

- (IBAction)testButton:(id)sender {

    changeLabel.String = @"Changed !";

}

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

Hope this will help you.



来源:https://stackoverflow.com/questions/23819273/how-to-change-labels-text-from-a-button-on-a-ccscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!