タグを使ってみてもいいかもしれません。タグ 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