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

时间:2012-12-04 02:06:57

标签: 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 = [[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++;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以致电viewWithTag

来获取正确的文字字段
UITextField *myField = (UITextField*)[self.view viewWithTag:15];
// Now that I have my field, I can write some text into it:
myField.text = @"X";