示例: textfield1 textfield2 textfield3 textfield4 textfield5
button
问题: 在iOS中有5个文本字段,假设按钮为值1.当第一次按下按钮时,值1应显示在第一个文本字段中,按钮值应增加到2.按下按钮时第二个时间,值2应显示在第二个文本字段中,按钮值应增加到3.对所有5个值同样继续。
答案 0 :(得分:2)
也许您可以尝试使用标签。使用标记1到5设置文本字段,然后实现视图控制器,如下所示:
#import "ButtonValueViewController.h"
@interface ButtonValueViewController ()
// Properties
@property (nonatomic) int buttonValue;
// Actions
- (IBAction)buttonTapped:(UIButton *)sender;
@end
@implementation ButtonValueViewController
@synthesize buttonValue;
// ...
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialise buttonValue to 1
self.buttonValue = 1;
}
- (IBAction)buttonTapped:(UIButton *)sender
{
// Get the textfield with the tag number the same as buttonValue
UITextField * textField = (UITextField *)[self.view viewWithTag:self.buttonValue];
// Set textfield's text to buttonValue
textField.text = [NSString stringWithFormat:@"%d", self.buttonValue];
// Increment buttonValue
self.buttonValue++;
}
@end