gpt4 book ai didi

mysql - 如何添加警报 'if data parameter = nil'

转载 作者:行者123 更新时间:2023-11-29 02:52:45 25 4
gpt4 key购买 nike

您好,如果我无法连接到 Web 服务,我正在尝试创建一个警报。本质上,如果我看到'data parameter is nil',那么我想要一个警告说“无法连接,然后返回。”

这是我为此使用的代码。

- (IBAction)search:(id)sender
{


if ([hostTextField.text isEqualToString:@""] || [passwordTextField.text isEqualToString:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camaleon Alert" message:@"All fields must be filled in" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];


}else{




NSString *requestStr = @"http://";
requestStr = [requestStr stringByAppendingString:hostTextField.text];
requestStr = [requestStr stringByAppendingString:@":8080/dblist.php?password="];
requestStr = [requestStr stringByAppendingString:passwordTextField.text];


NSURL * url = [NSURL URLWithString:requestStr];
NSData * data = [NSData dataWithContentsOfURL:url];


json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];


DBList = [[NSMutableArray alloc]init];

for (int i = 0; i < json.count; i++)
{
//Create the objects

NSString * dbName = [[json objectAtIndex:i] objectForKey:@"Database"];


//------------------------------------------

Database * myDatabases = [[Database alloc]initWithDatabaseName: (NSString *) dbName];

//Add the object to the array


[DBList addObject:myDatabases];

}

[self.DBTable reloadData];

感谢您的任何建议。

最佳答案

所以,逐字逐句:

“本质上,如果我看到‘数据参数为 nil’,那么我想要一个警告说‘无法连接,然后返回。’”

if(data == nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Problem" message:@"not able to connect" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
else
{
//The rest of your code
}

关于mysql - 如何添加警报 'if data parameter = nil',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24296984/

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