Objective c 仍然对警报不屑一顾

Objective c 仍然对警报不屑一顾,objective-c,ipad,delegates,uialertview,Objective C,Ipad,Delegates,Uialertview,在按下任一按钮(1和2)后,我试图保持此UIAlertView向上 单击“+”按钮或“-”按钮后,我可以看到UILabel文本增量,然后它关闭UIAlertView 这是我目前正在使用的: #pragma Alert View Methods -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { [self dismissWithClickedButtonInd

在按下任一按钮(1和2)后,我试图保持此
UIAlertView
向上

单击“+”按钮或“-”按钮后,我可以看到
UILabel
文本增量,然后它关闭
UIAlertView

这是我目前正在使用的:

#pragma Alert View Methods

-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
        [self dismissWithClickedButtonIndex:buttonIndex animated:animated];

}

#pragma count functions
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1 || buttonIndex == 2) {
        return;
    }
    else{

        [self dismissWithClickedButtonIndex:buttonIndex animated:YES];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        self.currentCountButtonCount++;
        [self.countAlert setMessage:[NSString stringWithFormat:@"%d",self.countButtonCount + 1]];

    }if (buttonIndex == 2) {
        self.currentCountButtonCount--;
        [self.countAlert setMessage:[NSString stringWithFormat:@"%d",self.countButtonCount - 1]];

    }
}

- (IBAction)countClick:(id)sender {


    // tallies and keeps current count number

    if (!self.currentCountButtonCount)
         self.currentCountButtonCount = 0;

   NSString *alertMessage = [NSString stringWithFormat:@"%d", self.countButtonCount];

    self.countAlert = [[UIAlertView alloc]initWithTitle:@"Count" message:alertMessage delegate:self cancelButtonTitle:@"end" otherButtonTitles:@"+",@"-", nil];

   [self.countAlert show];
}
在我的最后一个问题上,有人告诉我按照自己的习惯来做,这就是我现在正在尝试的,但它仍然会关闭UIAlert


标签更改时,我如何保持它,直到它们触碰结束按钮为止?

您使用的是AlertView的默认按钮,单击该按钮后,它将自动取消AlertView

因此,您必须以编程方式创建按钮,并在alertview中添加这些按钮,如:

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[btn setTitle:@"+" forState:UIControlStateNormal];
[countAlert addSubview:btn ]; 
在此btn上调用您的方法

因此,您必须创建两个带有“+”和“-”的自定义按钮。并在AlertView中添加该按钮。


我不想在你的游行中下雨,但如果你认为警报视图是处理变量递增/递减的最佳方式,我建议你重新考虑你的设计

UIAlertView用于提供暂时信息和简化决策。一个简单的“你确定吗?”是警报视图用法的教科书示例

从用户的角度来看,能够修改滑块中的所有属性或任何其他形式的永久性输入,然后在确定的情况下,点击带有警报视图(或确认屏幕)的确认按钮,会让人感到更舒服。在警报视图中执行此操作不仅容易出错,而且与其他iOS的工作方式相比,这是违反直觉的


如果您在应用程序中安装另一种形式的输入时遇到问题,请阅读如何执行动画并根据需要显示控件,将输入隐藏在UIAlertView中对您来说是最简单的解决方案,但对用户来说不是最好的。

我会为此改写什么方法@Bazinga您根本不应该覆盖警报。谢谢,您的回答帮助我获得了正确的外观和感觉。
-(void)setAlertValue:(id)sender{

    switch ([sender tag]) {
        case 1:
        {
           // currentCountButtonCount++;

            [self.countAlert setMessage:[NSString stringWithFormat:@"%d",++countButtonCount]];
        }
            break;
        case 2:
        {
            //currentCountButtonCount--;

            [self.countAlert setMessage:[NSString stringWithFormat:@"%d",--countButtonCount]];
        }
            break;
        default:
            break;
    }
}

- (IBAction)countClick:(id)sender {
// tallies and keeps current count number

    if (!currentCountButtonCount)
        currentCountButtonCount = 0;

    NSString *alertMessage = [NSString stringWithFormat:@"%d", countButtonCount];

    self.countAlert = [[UIAlertView alloc]initWithTitle:@"Count" message:alertMessage delegate:self cancelButtonTitle:@"end" otherButtonTitles:nil, nil];


    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 40, 20)];
    [btn addTarget:self action:@selector(setAlertValue:) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundColor:[UIColor greenColor]];
    btn.tag = 1;

    [btn setTitle:@"+" forState:UIControlStateNormal];

    UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(230, 50, 40, 20)];
    [btn1 addTarget:self action:@selector(setAlertValue:) forControlEvents:UIControlEventTouchUpInside];
    [btn1 setBackgroundColor:[UIColor redColor]];
    btn1.tag = 2;

    [btn1 setTitle:@"-" forState:UIControlStateNormal];
    [countAlert addSubview:btn];
    [countAlert addSubview:btn1];
    [self.countAlert show];

}