iphone:点击一个按钮,按钮的标题应该打印在另一个按钮上

时间:2012-05-07 13:45:36

标签: iphone objective-c ios5

我想从下面的图片中创建功能

enter image description here

在此图片中有按钮'A','A','C','E'等。

现在单击此按钮我想在第一个空白框中显示该按钮的文本,然后在单击另一个按钮后,我想在第二个空白框中显示该按钮的文本。

如何实现此类功能。

任何想法?

3 个答案:

答案 0 :(得分:1)

让那些按钮“A”,“A”,“C”,“E”等共享一个共同的动作方法,如

-(void)blueButtonClick:(id)sender {

    UIButton* blueButton = (UIButton*)sender; // we got the button reference here whichever is clicked

    // suppose those white box is a UITextField

    if([self.textField1.text length] == 0){
        self.textField1.text = blueButton.currentTitle;
    } else if([self.textField2.text length] == 0) {
        self.textField2.text = blueButton.currentTitle;
    } else if([self.textField3.text length] == 0) {
        self.textField3.text = blueButton.currentTitle;
    } else if([self.textField4.text length] == 0) {
        self.textField4.text = blueButton.currentTitle;
    } else if([self.textField5.text length] == 0) {
        self.textField5.text = blueButton.currentTitle;
    } else {
        NSLog(@" I am full now .... Sorry !!");
    }

}

答案 1 :(得分:0)

使用iboutlet属性,并将它们连接到您的按钮,然后在其他按钮cliks时更改其文本

喜欢

-(IBAction) butoonAPressed;
{
 self.buttonC.text = self.buttonA.text;
self.buttonB.text = self.buttonA.text;
}

或使用标签来证明按下哪个按钮并将所有按钮文本保存在一个数组中,然后根据标记进行检索。

答案 2 :(得分:0)

您应该为当前空框实现按钮操作设置文本(在这种情况下,框=具有白色背景的按钮)。你需要做的是保持轨道哪个按钮已经填满,哪个是下一个按钮(你可以考虑使用UIButton标签或其他方法来跟踪按钮)。

另外:你应该有办法让人们能够删除最后一个方框值(如果他们意外按错了按钮)。

亲切的问候,