2011-10-11 110 views
3
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    .... 
} 

我正在开发iPhone应用程序的Xcode。我可以将参数传递给iphone方法的clickedButtonAtIndex吗?

当我点击UIAlertView的按钮时,我必须修改该方法中的一些局部变量。

我想在该方法中控制一些局部变量。

那么有没有办法将变量作为参数传递?

回答

3

不,你不能传递其他任何东西到那个方法,但是如果你打算修改局部变量那么有什么意义呢?如果你想使用关于那个方法的一些信息,你必须在一个实例中设置这些信息变量。

self.myInstanceVariable = valueIWillNeedWhenClicked; 
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]; 
    alertView.delegate = self; 

    [alertView show]; 
    [alertView release]; 

Then on method: 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *valueINeed = self.myInstanceVariable 
} 

因此,例如,显示您的AlertView这样的事情之前,

相关问题