Saving textField data to a property in an NSObject Class - ios

I am quite new to iOS development so please be nice :) I am developing an app at the moment. A user will register by filling in a form which is just a bunch of TextFields.
Once the user registers they will be redirected to their homePage where a UIImageView and a UILabel will display there data they used when registering.
Now my issue is how to ensure that this UIImageView and UILabel display the same data everytime that same user logs in. I tried this using NSUserDefaults but when the user logs in it would display the users data that i just registered with. Any suggestions would be great and also I am using parse for my data base.
Here is the code for when a user registers
NSLog(#"Registering user");
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = #"Registering";
PFObject *parent = [PFObject objectWithClassName:#"Parent"];
UIImage *image = form.profilePhoto;
NSData *imageData = UIImageJPEGRepresentation(image, 0.6);
PFFile *imageFile = [PFFile fileWithName:#"image.jpeg" data:imageData];
parent[#"Name"] = form.name;
parent[#"Email"] = form.email;
parent[#"Password"] = form.password;
parent[#"Location"] = form.location;
parent[#"ImageFile"] = imageFile;
[parent saveInBackground];
[parent saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
[hud hide:YES];
currentUser = YES;
//saveData to parentUser
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:form.name forKey:#"Name"];
//Send user to parent home page
PHomeViewController *lvc=[self.storyboard instantiateViewControllerWithIdentifier:#"Phome"];
SlideNavigationController *navcontroller = [[SlideNavigationController alloc] initWithRootViewController:lvc];
ParentMenu *leftMenu = (ParentMenu*)[self.storyboard instantiateViewControllerWithIdentifier: #"LeftMenuViewController"];
[self.navigationController pushViewController:lvc animated:YES];
navcontroller.leftMenu = leftMenu;
//save data to nsuserdefualts
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
UIImage *uploadPhoto = form.profilePhoto;
[defaults setObject:form.name forKey:#"Name"];
[defaults setObject:UIImageJPEGRepresentation(uploadPhoto, 0.6) forKey:#"ImageFile"];
[defaults synchronize];
NSLog(#"Data has been saved");
}
else {
NSLog(#"There was an error in registration");
}
}];
}
}
And this is the code that runs when a user logs in
(IBAction)login:(id)sender {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = #"Loading...";
PFQuery *query = [PFQuery queryWithClassName:#"Parent"];
[query whereKey:#"Email" equalTo:_Email.text];
[query whereKey:#"Password" equalTo:_Password.text];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (object) {
NSLog(#"User logged in successfully");
//Send user to parent home page
PHomeViewController *lvc=[self.storyboard instantiateViewControllerWithIdentifier:#"Phome"];
SlideNavigationController *navcontroller = [[SlideNavigationController alloc] initWithRootViewController:lvc];
ParentMenu *leftMenu = (ParentMenu*)[self.storyboard instantiateViewControllerWithIdentifier: #"LeftMenuViewController"];
[self.navigationController pushViewController:lvc animated:YES];
navcontroller.leftMenu = leftMenu;
} else {
// LOGIN ERROR
UIAlertView *ALERT = [[UIAlertView alloc]initWithTitle:#"Error" message:#"There was an error logging in please try again later." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[ALERT show];
_Email.text = [NSString stringWithFormat:#""];
_Password.text = [NSString stringWithFormat:#""];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}];
}
Thanks!

Related

fetching 1 image from parse.com

Ive seen many posting on here with phenomenal answers by the community. Unfortunately none have been able to help or guide me to what i need help with. Im trying to "fetch" the image that the "current user" uploaded to parse on the same "UIImageView"
below is the example of how i uploaded the photo
myaccount.h
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)UploadPhoto:(id)sender;
- (IBAction)selectPhoto:(id)sender;
myaccount.m
- (IBAction)UploadPhoto:(UIButton *)sender {
PFObject *User = [PFUser currentUser];
NSData *imageData = UIImageJPEGRepresentation(_imageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:#"%#.png", _username.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[User setObject:imageFile forKey:#"ProfilePicture"];
// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Uploading";
[hud show:YES];
// Upload Profile Picture to Parse
[User saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
[hud hide:YES];
if (!error) {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Complete" message:#"Successfully uploaded profile picture" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
// Dismiss the controller
//[self dismissViewControllerAnimated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
}
i honestly have no idea where to go from here! the photo uploads perfectly to the class on parse.com... but i cannot get it to show everytime the app viewdidloads this controller.
i tried
- (void)viewDidLoad {
[super viewDidLoad];
PFFile * myPFFile = [[PFUser currentUser] objectForKey:#"ProfilePicture"];
[myPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:data];
// image can now be set on a UIImageView
}
}];
but i get unused variable for "image" on UIImage *image = [UIImage imageWithData:data];
what am i doing wrong. Someone please help me with any codes I'm missing. I've been at this for 3 months now and its stopping me from moving forward.... PPPPLLZZZ help
What am I missing? Do you put the image inside an imageView?
(thats why you get 'unused variable for "image"')
in your case:
[imageView setImage:image];

How to get User Image from class "User" in UIImageView? Parse.com

I want to download the image in a UIImageView user from Parse. In the User section, I created the UserImage section, but I can not download it into UIImageView, what should I do? You give me a hand? Help me please.
I've used this code:
PFUser* currentUser = [PFUser currentUser];
if (currentUser) {
PFQuery* queryPhoto = [PFQuery queryWithClassName:#"UserImage"];
[queryPhoto findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// Verify if there are no errors
if (!error) {
// Retrieve Usename
User.text = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"username"]] ;
// Retrieve Photo
PFUser *currentuser = [PFUser currentUser];
PFFile *file = [currentuser objectForKey:#"UserImage"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:data];
// image can now be set on a UIImageView
self.UserImages.image = image;
}
}];
}
else {
NSString *errorString = [[error userInfo] objectForKey:#"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:errorString delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
} ];
}
Parse.com has the PFImageView specifically to make this task eaiser.
Try this:
PFUser* currentUser = [PFUser currentUser];
if (currentUser) {
PFQuery* queryPhoto = [PFQuery queryWithClassName:#"UserImage"];
[queryPhoto findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// Verify if there are no errors
if (!error) {
// Retrieve Usename
User.text = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"username"]] ;
// Retrieve Photo & Load
PFFile *file = [currentUser objectForKey:#"UserImage"];
PFImageView *imageView = [[PFImageView alloc] init];
self.UserImages.image = imageView; //Assuming here that you set self.UserImages.image as a PFImageView
self.UserImages.image.file = file;
[self.UserImages.image loadInBackground];
}
else {
NSString *errorString = [[error userInfo] objectForKey:#"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:errorString delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
}];
}

Adding profile picture at user signup using Parse - iOS

I'm trying to create a New User using Parse.com as my backend. I was able to successfully register the user's info. But, my problem is saving the user's profile picture along with it. After the user selects the picture using the camera or photo library, I am presenting an image editor (https://github.com/heitorfr/ios-image-editor) using a .xib file. This all works fine with no problems. Then the image is placed in the UIImageView box and the user proceeds to fill in the Username, email and password and they click signup. The problem is after they sign up and all the info gets placed in the table via Parse, the image container seems to be empty. When I click on the image file, the picture is not there. I can't seem to figure out what I'm doing wrong.
View Did Load
- (void)viewDidLoad {
[super viewDidLoad];
self.addPhotoImageView.contentMode = UIViewContentModeScaleAspectFill;
// Create add photo popup
self.addPhotoActionSheet = [[UIActionSheet alloc] initWithTitle:#"Select source" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Take photo", #"Choose photo", nil];
// Create image picker
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.editing = YES;
}
Image Picker Controller Delegate Methods
// Switches to the image editing view
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.imagePicker dismissViewControllerAnimated:NO completion:nil];
if (self.imageEditorViewController == nil) {
self.imageEditorViewController = [[HFImageEditorViewController alloc] initWithNibName:#"ImageEditor" bundle:nil]; }
self.imageEditorViewController.sourceImage = image;
self.imageEditorViewController.rotateEnabled = NO;
self.imageEditorViewController.checkBounds = YES;
[self.imageEditorViewController reset:NO];
__weak typeof(self) weakSelf = self;
self.imageEditorViewController.doneCallback = ^(UIImage *editedImage, BOOL canceled) {
if (!canceled) {
[weakSelf.addPhotoImageView setImage:editedImage];
}
// Hide editor
[weakSelf.imageEditorViewController dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:self.imageEditorViewController animated:NO completion:nil]; }
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil]; }
UIActionSheetDelegate methods
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case 1:
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
default:
return;
}
[self presentViewController:self.imagePicker animated:YES completion:nil]; }
Here is IBAction signup code:
- (IBAction)signup:(id)sender {
NSData *imageData = UIImageJPEGRepresentation(self.chosenImage, 0.5f);
PFFile *imageFile = [PFFile fileWithName:#"Profileimage.jpg" data:imageData];
NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *email = [self.emailField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([username length] == 0 || [email length] == 0 || [password length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Oops" message:#"Make sure you fill in all the fields!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {
PFUser *newUser = [PFUser user];
newUser[#"ProfilePic"] = imageFile;
newUser.username = username;
newUser.email = email;
newUser.password = password;
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:[error.userInfo objectForKey:#"error"] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
}
There's no indication from the Parse.com API docs that any information other than password and username are set when using - signUpInBackgroundWithBlock:
You will have to sign up the user first, then have a nested call within the PFBooleanResultBlock of the signUp method to perform
else {
PFUser *newUser = [PFUser user];
newUser.username = username;
newUser.email = email;
newUser.password = password;
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:[error.userInfo objectForKey:#"error"] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {
newUser[#"ProfilePic"] = imageFile;
[newUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (! error) {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
}];
}
You need to set it up to where you are sending a file to the database, since Parse will store images as such. Here's how I save images in my projects.
.h file:
#property (nonatomic, weak) IBOutlet UITextField *username
#property (nonatomic, weak) IBOutlet UITextField *email;
#property (nonatomic, strong) IBOutlet UIImageView *photo;
#property (nonatomic, strong) IBOutlet UIButton *addUserPhoto;
.m file in your save method
NSString *username = _username.text;
NSString *email = _email.text;
PFObject *newUser = [PFObject objectWithClassName:#"User"];
[newUser setObject:username forKey:#"username"];
[newUser setObject:email forKey:#"email"];
// image
NSData *imageData = UIImageJPEGRepresentation(_photo.image, 0.8);
NSString *filename = [NSString stringWithFormat:#"%#.png", _name.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[newUser setObject:imageFile forKey:#"profileImage"];
Replace _Photo with whatever you named the image view. It will set the uploaded image to this view.

MBProgressHUD not showing from another class

I'm getting values from Parse Cloud by pressing a button. The code for getting the data data from Parse is in another class, but when I try to show the MBProgessHUD from that class it doesn't do anything.
No errors either. However, if I do all in the same class, it works. Not sure how to display the progressHUD from another class on a specific view which is open at that time.
- (IBAction)testWeather:(id)sender {
Reports * obje2 = [[Reports alloc]init];
[obje2 startGetting];
}
// in reports class
-(void) startGetting {
Names= [[NSMutableArray alloc] init];
Latitude= [[NSMutableArray alloc] init];
Longitude= [[NSMutableArray alloc] init];
[Names removeAllObjects];
[Latitude removeAllObjects];
[Longitude removeAllObjects];
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *CountyName = [standardUserDefaults stringForKey:#"CurrentlySelectedCounty"];
PFQuery *query = [PFQuery queryWithClassName:#"Reports"];
[query whereKey:#"County" equalTo:#"Universal"];
//
NSInteger countTotal= [query countObjects];
NSString *totalVals = [NSString stringWithFormat: #"%d", (int)countTotal];
[[NSUserDefaults standardUserDefaults] setObject:totalVals forKey:#"NumberOfSwamps"];
//
NSString * storyboardName = #"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"browsePage"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:vc.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Loading Reports";
[hud show:YES];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[hud hide:YES];
if (!error) {
for (PFObject *obj in objects) {
NSString *LastName = [obj objectForKey:#"Name"] ;
NSString *Lat = [obj objectForKey:#"Latitude"] ;
NSString *Lon = [obj objectForKey:#"Longitude"] ;
// add values to array
[Names addObject:LastName];
[Latitude addObject:Lat];
[Longitude addObject:Lon];
[self getResults];
}
}
else{
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
}
Trying another way...but this doesn't work either...even though HUD is running from the original class.
browse.m,
if (myInt == 8){
NSLog(#"\n \n Pressed the refresh icon for reports");
[self removeAllAnnotations];
[standardUserDefaults setInteger:1 forKey:#"HUD_Switch"]; // to make sure switching on
[standardUserDefaults synchronize];
[self HUDSwitcher];
Reports * obje2 = [[Reports alloc]init];
[obje2 startGetting];
}
-(void) HUDSwitcher{
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSInteger myInt = [standardUserDefaults integerForKey:#"HUD_Switch"]; // 0 for switched off .... 1 for switched on
NSString * storyboardName = #"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"browsePage"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:vc.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Testing";
[hud show:YES];
if (myInt==0) {
[hud hide:YES];
}
}
reports.m
[standardUserDefaults setInteger:1 forKey:#"HUD_Switch"]; // to switch on the HUD value
browsePage * obje2 = [[browsePage alloc]init];
[obje2 HUDSwitcher];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[standardUserDefaults setInteger:0 forKey:#"HUD_Switch"];
[standardUserDefaults synchronize];
browsePage * obje2 = [[browsePage alloc]init];
[obje2 HUDSwitcher];
if (!error) {
for (PFObject *obj in objects) {
NSString *LastName = [obj objectForKey:#"Name"] ;
NSString *Lat = [obj objectForKey:#"Latitude"] ;
NSString *Lon = [obj objectForKey:#"Longitude"] ;
// add values to array
[Names addObject:LastName];
[Latitude addObject:Lat];
[Longitude addObject:Lon];
[self getResults];
}
}
else{
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
}
When you instantiate the new UIViewController vc, it is not in the current view stack, so if you display a progressHUD on its view it won't appear on the screen.
You should display the progressHUD from the view of the initial viewController.
One way to solve this would be with delegation like this:
- (IBAction)testWeather:(id)sender {
self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Loading Reports";
[hud show:YES];
Reports * obje2 = [[Reports alloc]init];
[obje2 startGettingWithDelegate:self];
}
- (void)reports:(Reports*)report didFinishGetting
{
[self.hud hide:YES];
}
In yourViewController interface in the .h file add this:
#property (nonatomic, strong) MBProgressHUD *hud;
In Reports Class
-(void) startGettingWithDelegate:id<yourProtocol> delegate {
Names= [[NSMutableArray alloc] init];
Latitude= [[NSMutableArray alloc] init];
Longitude= [[NSMutableArray alloc] init];
[Names removeAllObjects];
[Latitude removeAllObjects];
[Longitude removeAllObjects];
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *CountyName = [standardUserDefaults stringForKey:#"CurrentlySelectedCounty"];
PFQuery *query = [PFQuery queryWithClassName:#"Reports"];
[query whereKey:#"County" equalTo:#"Universal"];
//
NSInteger countTotal= [query countObjects];
NSString *totalVals = [NSString stringWithFormat: #"%d", (int)countTotal];
[[NSUserDefaults standardUserDefaults] setObject:totalVals forKey:#"NumberOfSwamps"];
//
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// Inform Delegate that finished loading
[delegate reports:self didFinishLoading];
if (!error) {
for (PFObject *obj in objects) {
NSString *LastName = [obj objectForKey:#"Name"] ;
NSString *Lat = [obj objectForKey:#"Latitude"] ;
NSString *Lon = [obj objectForKey:#"Longitude"] ;
// add values to array
[Names addObject:LastName];
[Latitude addObject:Lat];
[Longitude addObject:Lon];
[self getResults];
}
} else {
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
}
To do this right you should create a #protocol in Reports.h and make you viewController conform to it.
In Reports.h
#protocol ReportsProtocol
- (void)reports:(Reports*) finishedLoading;
#end
#interface ...
.
.
.
In yourViewController.h
#interface YourViewController : UIViewController <ReportsProtocol>
.
.
.
Another solution can be using blocks. Its a little more complicated but cleaner.

Parse 122 error upload

If I save text without having any text in the field I get this error message in Parse.com: Update Failure - The operation couldn't be completed(Parse error 122.) If I press OK and then try to dismiss the view with Cancel(a button item) the app crashes. I think a valid file name at Parse.com has to contain at least 1 character. Maybe I can do do something to stop the user from saving when not enter text? Any ideas?
This my code:
- (IBAction)save:(id)sender {
// Create PFObject with profile information
PFUser *profile = [PFUser currentUser];
[profile setObject:nameTextField.text forKey:#"name"];
[profile setObject:titleTextField.text forKey:#"title"];
[profile setObject:locationTextField.text forKey:#"location"];
// Profile image
NSData *imageData = UIImageJPEGRepresentation(profileImageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:#"%#", nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:#"profileimageFile"];
// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Updating";
[hud show:YES];
// Upload profile to Parse
if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)
[hud hide:YES];
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
[[[UIAlertView alloc] initWithTitle:#"Profile Information" message:#"Fill in atleast one field" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
[hud hide:YES];
}
else {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Successfully updated profile" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[hud hide:YES];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"profile" sender:self];
}
}];
}
- (IBAction)Cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"profile" sender:self];
}
1
Test if your one letter theory is true. Change:
NSString *filename = [NSString stringWithFormat:#"%#", nameTextField.text];
To:
NSString *filename = [NSString stringWithFormat:#"file%#", nameTextField.text];
2
Or just avoid it if it's blank. So this:
NSString *filename = [NSString stringWithFormat:#"%#", nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:#"profileimageFile"];
Becomes:
if (nameTextField.text) {
NSString *filename = [NSString stringWithFormat:#"%#", nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:#"profileimageFile"];
}
3
Also, what is this:
if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)
It's doesn't appear to be connected to anything?
4
You call this twice in quick succession, and then again right after the file saves. Is there something in the method that makes the repetitive calls necessary?
[hud hide:YES];
5
Your if statement doesn't appear to be connected to anything:
if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)
I'm assuming you want:
if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0) {
[hud hide:YES];
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
[[[UIAlertView alloc] initWithTitle:#"Profile Information" message:#"Fill in atleast one field" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
[hud hide:YES];
}
else {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Successfully updated profile" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[hud hide:YES];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"profile" sender:self];
}
}];
}

Resources