Tags 如何从其他方法中写入textField.tag=15?

Tags 如何从其他方法中写入textField.tag=15?,tags,xcode4.5,Tags,Xcode4.5,此代码绘制多个文本字段并指定标记,并将标记号写入每个字段。我如何在标签号为15的文本字段中写入X - (void)viewDidLoad { int z = 0; [super viewDidLoad]; for (int y = 10; y < 300; y = y + 25) { for (int x = 10; x < 300; x = x + 25) { textField = [[UIT

此代码绘制多个文本字段并指定标记,并将标记号写入每个字段。我如何在标签号为15的文本字段中写入X

- (void)viewDidLoad
{
    int z = 0;
    [super viewDidLoad];
    for (int y = 10; y < 300; y = y + 25)
    {
        for (int x = 10; x < 300; x = x + 25)
        {
            textField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, 25, 25)];
            textField.borderStyle = UITextBorderStyleLine;
            textField.textColor = [UIColor blackColor];
            textField.font = [UIFont fontWithName:@"ArialMT" size:16];
            textField.backgroundColor = [UIColor whiteColor];
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            textField.backgroundColor = [UIColor clearColor];
            textField.textAlignment = NSTextAlignmentCenter;
            textField.enabled = NO;            
            textField.text = [NSString stringWithFormat:@"%d", z];
            [self.view addSubview:textField];
            textField.tag = z++;
        }
    }
}

您可以通过调用viewWithTag获得正确的文本字段:

UITextField *myField = (UITextField*)[self.view viewWithTag:15];
// Now that I have my field, I can write some text into it:
myField.text = @"X";