简体   繁体   中英

iphone:On click of one button the title of button should be print on another button

I want to create the functionality from below image

在此处输入图片说明

In this image there are buttons 'A','A','C','E' etc.

Now on click of this button I want the text of that button in the first blank box and then after clicking another button i want the text of that button on the 2nd blank box.

How can I implement this kind of functionality.

Any Idea?

let those buttons 'A','A','C','E' etc shares a common action method like

-(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 !!");
    }

}

use iboutlet properties, and connect them to your buttons, then change its text whenver other button cliks

like

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

or use tags to justify which button is pressed and save all buttons text in an array, and retrive on the basis of tag.

You should implement button actions setting text for the current empty box (in this case box=button with white background). What you have to do is keep the track which button(s) have been filled and which is next button (you might consider using UIButton tag or other approach to keep track of the button).

Also: You should have a way for people to be able to erase the last box value (in case they accidentally press wrong button).

Kind regards,
Bo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM