gpt4 book ai didi

iphone - 多个 alertViews 创建错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:06 24 4
gpt4 key购买 nike

你好,下午好,我遇到了一些问题,老实说,我不明白我必须为具有不同消息的同一屏幕创建不同的 alertViews,这些警报中的大多数只有 1 个按钮,但是有一个要删除需要 2 个按钮,问题是,因为其他人只有 1 个按钮,当我创建2 按钮屏幕 View ,我添加了 (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 方法,我遇到了一些问题

一些代码在这里

- (IBAction)saveInfo{
if (med.text.length ==0) {
UIAlertView *alertViewError = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"")
message:NSLocalizedString(@"EMPTY1",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewError show];
[alertViewError release];
}
else if(medicamento.text.length >= 41){
[self lenghtError:40:NSLocalizedString(@"TF_MED",@"")];
}
else if (med.text.length ==0 || descripcion.text.length == 0) {
UIAlertView *alertViewError = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"")
message:NSLocalizedString(@"EMPTY2",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewError show];
[alertViewError release];
}
else if (descripcion.text.length >= 41){
[self lenghtError:40:NSLocalizedString(@"TF_DESCRIPCION",@"")];
}
else{
[self insertDictionary];
UIAlertView *alertViewAcept = [[UIAlertView alloc] initWithTitle:@""
message: NSLocalizedString(@"ACCEPT_MSG",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertViewAcept show];
[alertViewAcept release];
[self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)cancelData{
UIAlertView *alertViewCancel =
[[UIAlertView alloc] initWithTitle: NSLocalizedString(@"BT_DELETE_MED",@"")
message: NSLocalizedString(@"MSG_DELETE_MED",@"")
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: @"Cancel", nil];
[alertViewCancel setTag:999];
[alertViewCancel show];
[alertViewCancel release];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 999) {
if(buttonIndex==0){
[self.Bayer_DB_obj deleteRowWithKeyValue:[NSString stringWithFormat:@"%d",IdMed] onKeyName:@"id_ctl_med" onTable:@"ctl_med"];
// code to delete here
[self.navigationController popViewControllerAnimated:YES];
}
}

因此,在第一部分中,我创建了一些警报以指示用户他/她犯了错误,在第二部分中,我需要在删除前进行确认,但在这里,我需要 2 个按钮,然后,在第三部分,我有被调用的方法,我在警报中添加了一个标签以避免在所有警报中进行这种比较,问题是,当您显示 alertViewAcept 时,它会将您带到前一个 View Controller ,并且单击确定按钮(实际上是取消按钮标题)后,应用程序崩溃且没有任何“错误消息”

所以我不确定我做错了什么,请帮忙

最佳答案

我猜问题是您为 alertViewAcept 设置了委托(delegate),在显示警报后,您弹出 viewController,因此您的委托(delegate)将被释放,一旦警报上的按钮就会给您一个错误 View 被点击。

你应该这样做:

UIAlertView *alertViewAcept = [[UIAlertView alloc] initWithTitle:@"" 
message: NSLocalizedString(@"ACCEPT_MSG",@"")
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

更好的是,所有只有“确定”按钮的警报都不需要委托(delegate)。在这种情况下,您甚至不需要标签。

关于iphone - 多个 alertViews 创建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10887684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com