【发布时间】:2011-03-26 00:37:21
【问题描述】:
我有一个 UIAlertView(实际上是几个),如果用户不按取消,我正在使用方法 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 来触发操作。这是我的代码:
- (void)doStuff {
// complicated time consuming code here to produce:
NSString *mySecretString = [self complicatedRoutine];
int myInt = [self otherComplicatedRoutine];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"HERE'S THE STUFF"
message:myPublicString // derived from mySecretString
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Go On", nil];
[alert setTag:3];
[alert show];
[alert release];
}
然后我想做的事情如下:
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
if ([alertView tag] == 3) {
NSLog(@"%d: %@",myInt,mySecretString);
}
}
}
但是,此方法不知道mySecretString 或myInt。我绝对不想重新计算它们,也不想将它们存储为属性,因为-(void)doStuff 很少(如果有的话)被调用。有没有办法将这些额外信息添加到 UIAlertView 以避免重新计算或存储 mySecretString 和 myInt?
谢谢!
【问题讨论】:
标签: iphone ios uialertview