Last active
October 11, 2015 18:58
-
-
Save imrekel/3904628 to your computer and use it in GitHub Desktop.
bme-ios - iTravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - from UIImagePickerDelegate | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info | |
{ | |
UIImage* selectedImage = | |
info[UIImagePickerControllerOriginalImage]; | |
self.imageView.image = selectedImage; | |
[self dismissViewControllerAnimated:YES completion:nil]; | |
self.imageView.backgroundColor = [UIColor whiteColor]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ITEditTripViewController.h | |
// iTravel | |
// | |
@class ITEditTripViewController; | |
#import <UIKit/UIKit.h> | |
@interface ITEditTripViewController : UIViewController <UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> | |
@property (weak, nonatomic) IBOutlet UIImageView *imageView; | |
@property (weak, nonatomic) IBOutlet UITextField *nameTextField; | |
@property (weak, nonatomic) IBOutlet UITextField *locationTextField; | |
@property (weak, nonatomic) IBOutlet UITextView *descriptionTextView; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ITEditTripViewController.m | |
// iTravel | |
// | |
#import "ITEditTripViewController.h" | |
@interface ITEditTripViewController () | |
- (IBAction)textFieldDidEndOnExit:(id)sender; | |
- (IBAction)textFieldEditingDidBegin:(UITextField *)sender; | |
- (IBAction)textFieldEditingDidEnd:(UITextField *)sender; | |
- (void)handeImageViewTap:(UITapGestureRecognizer*)recognizer; | |
@end | |
@implementation ITEditTripViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handeImageViewTap:)]; | |
self.imageView.userInteractionEnabled = YES; | |
[self.imageView addGestureRecognizer:tapRecognizer]; | |
self.descriptionTextView.delegate = self; | |
} | |
- (void)viewDidUnload | |
{ | |
[self setImageView:nil]; | |
[self setNameTextField:nil]; | |
[self setLocationTextField:nil]; | |
[self setDescriptionTextView:nil]; | |
[super viewDidUnload]; | |
} | |
- (IBAction)textFieldDidEndOnExit:(id)sender | |
{ | |
[sender resignFirstResponder]; | |
} | |
- (IBAction)textFieldEditingDidBegin:(UITextField *)sender | |
{ | |
[UIView animateWithDuration:0.25 | |
delay:0 | |
options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState | |
animations:^{ | |
self.view.frame = CGRectOffset(self.view.frame, 0, -100); | |
} completion:nil]; | |
} | |
- (IBAction)textFieldEditingDidEnd:(UITextField *)sender | |
{ | |
[UIView animateWithDuration:0.25 | |
delay:0 | |
options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState | |
animations:^{ | |
self.view.frame = CGRectOffset(self.view.frame, 0, 100); | |
} completion:nil]; | |
} | |
- (void)handeImageViewTap:(UITapGestureRecognizer*)recognizer | |
{ | |
UIImagePickerController* pickerController = [[UIImagePickerController alloc] init]; | |
pickerController.delegate = self; | |
pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; | |
[self presentViewController:pickerController animated:YES completion:nil]; | |
} | |
#pragma mark - from UITextViewDelegate | |
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text | |
{ | |
if([text isEqualToString:@"\n"]) { | |
[textView resignFirstResponder]; | |
return NO; | |
} | |
return YES; | |
} | |
- (void)textViewDidBeginEditing:(UITextView *)textView | |
{ | |
[UIView animateWithDuration:0.25 | |
delay:0 | |
options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState | |
animations:^{ | |
self.view.frame = CGRectOffset(self.view.frame, 0, -210); | |
} completion:nil]; | |
} | |
- (void)textViewDidEndEditing:(UITextView *)textView | |
{ | |
[UIView animateWithDuration:0.25 | |
delay:0 | |
options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState | |
animations:^{ | |
self.view.frame = CGRectOffset(self.view.frame, 0, 210); | |
} completion:nil]; | |
} | |
#pragma mark - from UIImagePickerDelegate | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info | |
{ | |
UIImage* selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; | |
self.imageView.image = selectedImage; | |
[self dismissViewControllerAnimated:YES completion:nil]; | |
self.imageView.backgroundColor = [UIColor whiteColor]; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewWillAppear:(BOOL)animated | |
{ | |
if (self.trip) | |
{ | |
if (self.trip[@"image-name"]) | |
self.tripImageView.image = [UIImage imageNamed:self.trip[@"image-name"]]; | |
self.tripNameLabel.text = self.trip[@"name"]; | |
self.tripLocationLabel.text = self.trip[@"location"]; | |
self.tripDescriptionTextView.text = self.trip[@"description"]; | |
self.navigationItem.title = self.trip[@"name"]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
static NSString *CellIdentifier = @"TripsTableViewCell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
NSDictionary* tripData = | |
[_tripsDataMgr.trips objectAtIndex: indexPath.row]; | |
cell.textLabel.text = tripData[@"name"]; | |
cell.detailTextLabel.text = tripData[@"location"]; | |
NSString* tripImageName = tripData[@"image-name"]; | |
cell.imageView.image = [UIImage imageNamed:tripImageName]; | |
return cell; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - New methods | |
- (IBAction)editTripViewControllerDidSave:(UIStoryboardSegue *)unwindSegue | |
{ | |
ITEditTripViewController* viewController = unwindSegue.sourceViewController; | |
NSDictionary* tripDictionary = [NSDictionary dictionaryWithObjectsAndKeys: | |
viewController.nameTextField.text, @"name", | |
viewController.locationTextField.text, @"location", | |
viewController.descriptionTextView.text, @"description", | |
viewController.imageView.image, @"image", | |
nil]; | |
[_tripsDataMgr.trips addObject:tripDictionary]; | |
[self.tableView reloadData]; | |
} | |
- (IBAction)editTripViewControllerDidCancel:(UIStoryboardSegue *)unwindSegue | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PADDING 60.0 | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
if (indexPath.section == 0) | |
return 190; | |
else if (indexPath.section == 1 && indexPath.row == 2) | |
{ | |
CGSize textSize = [self.trip[@"description"] sizeWithFont:[UIFont systemFontOfSize:14.0] | |
constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping]; | |
return textSize.height+PADDING; | |
} | |
else | |
return self.tableView.rowHeight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment