ios - Objective-c - validate filled fields before publish item -
in application send info server , parse. have send image , need take category. when don't take category show user information.
but: how can check if user has filled in fields? in app take image , category?
this code show error when don't take category , send action:
- (ibaction)submititem:(uibutton *)sender { if ([category isequaltostring:@""]) { uialertview *alert = [[uialertview alloc] initwithtitle:@"category 'all' reserved" message:@"you need take different category" delegate:self cancelbuttontitle:nil otherbuttontitles:@"ok", nil]; [alert show]; return; } nsdata *imagedata = uiimagejpegrepresentation(imageview.image, 1.0); ///// send image server nsstring *urlstring = urlsavefullimagetoserver;
your alter simple using else statement...
- (ibaction)submititem:(uibutton *)sender { if ([category isequaltostring:@""]) { uialertview *alert = [[uialertview alloc] initwithtitle:@"category 'all' reserved" message:@"you need take different category" delegate:self cancelbuttontitle:nil otherbuttontitles:@"ok", nil]; [alert show]; return; } else { nsdata *imagedata = uiimagejpegrepresentation(imageview.image, 1.0); ///// send image server nsstring *urlstring = urlsavefullimagetoserver; ...
personally think improve approach not enable "send" button until of info complete.
set submit button enabled
property no
, when various pieces of info entered (the image, category) check see if finish - 1 time is, set enabled
yes
ios objective-c
No comments:
Post a Comment