Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ektoras Drandakis
29,580 PointsXcode: Show textfield text and image in collectionview using Parse
I want to show an image i've captured in a collectionview and the textfield text in a label in the header view can you tell me how can i do that? Here's the code where i send the request:
NSData *data = UIImageJPEGRepresentation(self.imageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@.png", self.groupField.text];
PFObject *share = [PFObject objectWithClassName:@"images"];
PFFile *imageFile = [PFFile fileWithName:filename data:data];
[share setObject:imageFile forKey:@"imageFile"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Uploading";
[hud show:YES];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// The image has now been uploaded to Parse. Associate it with a new object
PFObject *share = [PFObject objectWithClassName:@"images"];
[share setObject:imageFile forKey:@"imageFile"];
[share setObject:self.groupField.text forKey:@"groupName"];
[share saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"Saved");
[hud hide:YES];
[self performSegueWithIdentifier:@"returnHome" sender:nil];
} else {
// Error
NSLog(@"Error: %@ %@", error, [error userInfo]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error!"
message:@"Attempting request again!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}
}];
}
If possible please write the code in swift.