【发布时间】:2011-03-31 21:43:06
【问题描述】:
无论如何要在多个函数之间定义一些东西吗?我可以将它定义为一个,但在 {} 之外它不能被使用。我需要能够从创建的 UITextField 代码中获取来查看文本是什么。我使用的代码如下:
- (void)AlertShow32 {
UIAlertView * alert = [[ [ UIAlertView alloc ] initWithTitle:@"The Most Annoying Button!" message:@"What's your name?"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil ]autorelease];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];;
// [myTextField release];
[alert show ];
}
该函数将 myTextField 定义为 UIAlertView 中的文本框。
但我希望能够将 myTextField 文本保存为可以在以后的函数中访问的数据,例如在下面的代码中需要它的地方。
- (void)AlertShow33 {
UIAlertView * alert = [[[[ UIAlertView alloc ] initWithTitle:@"The Most Annoying Button!" message:@"Nice to meet you %i, you have a wierd name!", myTextField.text ]
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil ]autorelease];
alert.transform = CGAffineTransformTranslate( alert.transform, 0.0, 0.0 );
[alert show ];
}
如果有帮助,我在另一个函数中调用了不同的函数:
if (Alerttime == 31) {
[self performSelector:@selector(AlertShow31) withObject:self afterDelay:0.01];
}
if (Alerttime == 32) {
[self performSelector:@selector(AlertShow32) withObject:self afterDelay:0.01];
}
这只是调用这两个函数的部分,但我定义了Alerttime:
#define int *Alerttime;
Alerttime = 0;
有没有人知道如何在函数之后从 myTextField 访问文本?
【问题讨论】:
标签: ios xcode function textfield