首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIAlertView问题

UIAlertView问题
EN

Stack Overflow用户
提问于 2009-12-30 20:12:57
回答 2查看 446关注 0票数 0

我正在尝试对警报上按下的任何按钮采取行动。我有以下代码和第一个警报弹出,但它永远不会到达第二个。

我已经对其进行了设置,以便在标题中也定义UIAlertViewProtocol。

代码语言:javascript
复制
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != [actionSheet cancelButtonIndex])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something actually happened" message:@"Something was done" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"test",nil];
        [alert show];

    }

}

    -(void)alert:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex ==0)
    {
        NSLog(@"tetetete");
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [a show];
        [a release];
        [alert release];    
    }

}
EN

回答 2

Stack Overflow用户

发布于 2009-12-30 23:45:02

最简单的解释是没有正确设置委托。将调试器设置为if(buttonIndex ==0),以确保正在调用委托方法。或者,按钮索引可能不是零,因此永远不会创建第二个警报。调试器也可以检查这一点。

你应该移动线条..。

警报发布;

..。到第一个方法。

我从来没有尝试过像这样的菊花链警报。从理论上讲,由于警报是模式的,并且附加到窗口而不是顶视图,因此在第一个警报从窗口中完全删除之前,您不能添加第二个警报。如果窗口只是释放警报,则在原始对象尚未释放警报的情况下,警报可能会保留在窗口的某个属性中。保持视图直到第二个视图被显示之后可能会在窗口对象中引起某种类型的冲突。

票数 1
EN

Stack Overflow用户

发布于 2012-07-27 21:15:45

我已经修改了你的代码,检查一下

代码语言:javascript
复制
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != [actionSheet cancelButtonIndex])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something actually happened" message:@"Something was done" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"test",nil];
        [alert show];
        [alert release];

    }

}

    -(void)alert:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex ==0)
    {
        NSLog(@"tetetete");
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [a show];
        [a release];
        [a release];    
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1979881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档