gpt4 book ai didi

iphone - UIAlertView 无法显示并导致 “EXC_BAD_ACCESS” 错误

转载 作者:行者123 更新时间:2023-12-03 19:29:15 24 4
gpt4 key购买 nike

按下键盘上的返回按钮时会调用一个方法。调用另一个返回整数的方法后,将根据该整数创建一条消息。然后该消息被传递到 UIAlterView 并显示给用户。该警报没有任何选项(因此我不调用委托(delegate)),而只是通知用户发生了什么。

编辑:下面是完整的方法(之前显示的部分方法)。当我注释掉 UIAlertView 之前的所有内容并替换字符串 @"test"而不是传递消息时,警报将成功显示。我的结构是否没有正确处理内存?

- (IBAction)joinButton {
struct userInfo localUser;

[emailAddress resignFirstResponder];

//convert textField text to char array in structure
localUser.firstName = [self convertStringtoCharArray:firstName.text];
localUser.lastName = [self convertStringtoCharArray:lastName.text];
localUser.username = [self convertStringtoCharArray:username.text];
localUser.email = [self convertStringtoCharArray:emailAddress.text];
localUser.ipAddress = [self convertStringtoCharArray:localIPAddress.text];
localUser.latitude = currentLocation.coordinate.latitude;
localUser.longitude = currentLocation.coordinate.longitude;

//pass structure to be sent over socket
int result = [myNetworkConnection registerWithServer:&localUser];

NSString *message = nil;

//process result of sending attempt
if (result == 0) {
//registration succesful
message = [NSString stringWithString:@"Registration successful"];
} else if (result == 1) {
//server unavailable
message = [NSString stringWithString:@"Server unavailable. Please check your wi-fi settings and try again."];
} else if (result == 2) {
//unable to establish connection
message = [NSString stringWithString:@"Unable to communicate with server. Please check your wi-fi settings and try again."];
} else if (result == 3) {
//username already in use
message = [NSString stringWithString:@"Username in use. Try another username."];
}

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration"
message:message
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];

[alert show];
[alert release];
}

当我执行代码时,iPhone 变灰,就像即将显示警报但崩溃了。我在控制台中收到 EXC_BAD_ACCESS 错误。我是否没有正确发布警报或消息?这是控制台输出:

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) backtrace
#0 0x30011944 in objc_msgSend ()
#1 0x3054803e in NSPopAutoreleasePool ()
#2 0x3054c808 in -[NSAutoreleasePool release] ()
#3 0x30936ac4 in _UIApplicationHandleEvent ()
#4 0x3204696c in PurpleEventCallback ()
#5 0x30254a76 in CFRunLoopRunSpecific ()
#6 0x3025416a in CFRunLoopRunInMode ()
#7 0x320452a4 in GSEventRunModal ()
#8 0x308f037c in -[UIApplication _run] ()
#9 0x308eea94 in UIApplicationMain ()
#10 0x000020bc in main (argc=1, argv=0x2ffff508) at /Users/reu2009/Documents/iPhone Development/Development/BuddyTracker/main.m:14
(gdb) frame 10
#10 0x000020bc in main (argc=1, argv=0x2ffff508) at /Users/reu2009/Documents/iPhone Development/Development/BuddyTracker/main.m:14 14 int retVal = UIApplicationMain(argc, argv, nil, nil);

编辑:删除了[message release];并根据答案使用[NSString stringWithString];分配了字符串。

最佳答案

我遇到了这样的问题...我从后台线程调用 uiAlertView ....从主线程调用它

关于iphone - UIAlertView 无法显示并导致 “EXC_BAD_ACCESS” 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1088582/

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