#import "AddCityController.h"

#import "CityGuideDelegate.h"

#import "RootController.h"

#import "City.h";


@implementation AddCityController


#pragma mark ViewController Methods


- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

    [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}


- (void)viewDidLoad {

self.title = @"New City";

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveCity:)];

cityPicture = [UIImage imageNamed:@"QuestionMark.jpg"];

pickerController = [[UIImagePickerController alloc] init];

pickerController.allowsEditing = NO;

pickerController.delegate = self;

pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;


}


- (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}



- (void)dealloc {

[tableView release];

[nameCell release];

[pictureCell release];

[descriptionCell release];

[pickerController release];

    [super dealloc];

}


#pragma mark Instance Methods

- (void)saveCity:(id)sender {

CityGuideDelegate *delegate = (CityGuideDelegate *)[[UIApplication sharedApplication] delegate];

NSMutableArray *cities = delegate.cities;

UITextField *nameEntry = (UITextField *)[nameCell viewWithTag:777];

UITextView *descriptionEntry = (UITextView *)[descriptionCell viewWithTag:777];

if ( nameEntry.text.length > 0 ) {

City *newCity = [[City alloc] init];

newCity.cityName = nameEntry.text;

newCity.cityDescription = descriptionEntry.text;

newCity.cityPicture = cityPicture;

[cities addObject:newCity];

RootController *viewController = delegate.viewController;

[viewController.tableView reloadData];

}

[delegate.navController popViewControllerAnimated:YES];

}


- (IBAction)addPicture:(id)sender {

UITextField *nameEntry = (UITextField *)[nameCell viewWithTag:777];

[nameEntry resignFirstResponder];

[self presentModalViewController:pickerController animated:YES];

}


#pragma mark UIImagePickerController Methods


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[self dismissModalViewControllerAnimated:YES];


cityPicture = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

UIImageView *pictureView = (UIImageView *)[pictureCell viewWithTag:777];

pictureView.image = cityPicture;

[tableView reloadData];

}


#pragma mark UITableViewDataSource Methods


- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = nil;

if( indexPath.row == 0 ) {

cell = nameCell;

} else if ( indexPath.row == 1 ) {

UIImageView *pictureView = (UIImageView *)[pictureCell viewWithTag:777];

pictureView.image = cityPicture;

cell = pictureCell;

} else {

cell = descriptionCell;

}

return cell;

}


- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section {

return 3;

}


#pragma mark UITableViewDelegate Methods


- (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath {

CGFloat height;

if( indexPath.row == 0 ) {

height = 44;

} else if( indexPath.row == 1 ) {

height = 83;

} else {

height = 279;

}

return height;

}


@end


Posted by 김반장78
,

위 사진처럼 시뮬레이터 버전 수정해 주면 된다.

맥에서는 티스토리 사진 안올라가 지더니 갑자기 되네 고친건가..,
조금더 편하게 블로깅 할수 있을듯 ㅋ
Posted by 김반장78
,

한국에서 책이 도착했다

조금 읽어 봤는데 연습하면서 느낀점이 바로 나오더라는..
책은 잘산거 같다
일년에 한두권 사는 책이 참고서 아니면 학습서이니..ㅡ.ㅡ
Posted by 김반장78
,