自定义UIAlertView,代理上的消息更改



在我的客户端项目中,我需要在按下按钮时创建一个UIAlertView。那部分并不难,并且已经用所说的代码完成了:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        self.currentCountButtonCount++;
    }if (buttonIndex == 2) {
        self.currentCountButtonCount--;
    }
}
- (IBAction)countClick:(id)sender {
    //self.alertMessage = [[NSString alloc]init];
    // 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];
}

你会看到它毫无瑕疵地工作,但这不是我想要实现的。

我需要的是当用户按下UIAlertViews+按钮时,UIAlertView的消息变为递增的字符串,并在按下-按钮时显示递减的值。

我以为上面的代码会这样做,当按下任何按钮时,它都会解除警报。我需要它来保持警报,直到用户完成计数。

我将如何实现这一点?

我尝试过自定义UIAlertView,但它似乎只在图形方面有所帮助。

您可以使用自定义UIView筛选CustomAlertiew,然后为此`CustomAlertew创建delegates