0

在我的 UIAlertView 中,我想在按下“确定”按钮时打开另一个 UIView。

但问题是,即使在显示 UIView 后,警报仍保留在屏幕中,一旦消失,UIView 似乎已被禁用。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add details" message:@" Do you like to set the details now?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert show];
[alert release];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{   // the user clicked one of the OK/Cancel buttons
    NSString *title = [alertView title];

    if([title isEqualToString:@"Add details"])
    {
        .......

任何帮助,将不胜感激!

4

2 回答 2

0

为什么不检查委托方法中按下的按钮而不是标题?也就是说,在

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0){
        // User pressed "YES"
    }else{
        // User pressed "NO"
    }
}

取消按钮的索引为 0,其他按钮的索引增加。为了检测这是哪个警报,您还应该给它一个标签。希望这可以帮助。

于 2012-04-16T14:44:57.447 回答
0

可能是因为在实际关闭警报视图之前添加了新视图。所以最好使用didDismissWithButtonIndex委托来显示现有警报视图的按钮单击事件的新视图,而不是clickedButtonAtIndex

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
//Add the view
}

代替

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Add the view
}
于 2013-03-20T12:12:51.060 回答