Ios Objective-c-发布项目前验证填写的字段
在我的应用程序中,我将数据发送到服务器并进行解析。 但我必须发送图像,您需要选择类别。 当您不选择“类别”时,我将显示用户信息 但是:如何检查用户是否填写了所有字段?在我的应用程序中选择图像和类别 这是我的代码,当您不选择类别和发送操作时显示错误:Ios Objective-c-发布项目前验证填写的字段,ios,objective-c,Ios,Objective C,在我的应用程序中,我将数据发送到服务器并进行解析。 但我必须发送图像,您需要选择类别。 当您不选择“类别”时,我将显示用户信息 但是:如何检查用户是否填写了所有字段?在我的应用程序中选择图像和类别 这是我的代码,当您不选择类别和发送操作时显示错误: - (IBAction)submitItem:(UIButton *)sender { if ([category isEqualToString:@""]) { UIAlertView *alert = [[UIAler
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Category 'All' is reserved" message:@"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
return;
}
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
您的更改可以像使用else语句一样简单
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Category 'All' is reserved" message:@"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
return;
}
else {
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
...
我个人认为更好的方法是在所有数据完成之前不启用“发送”按钮
将submit按钮
enabled
属性设置为NO
,然后在输入各种信息(图像、类别)时检查是否所有内容都已完成-一旦完成,将enabled
设置为YES
您的问题是什么?