-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewTableViewController.m
More file actions
executable file
·172 lines (155 loc) · 5.03 KB
/
Copy pathNewTableViewController.m
File metadata and controls
executable file
·172 lines (155 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// NewTableViewController.m
// WifiCap
//
// Created by Junfeng Shen on 28/1/12.
// Copyright (c) 2012 SYSU. All rights reserved.
//
#import "NewTableViewController.h"
@implementation NewTableViewController
@synthesize nameT;
@synthesize locationT;
@synthesize descriptionT;
@synthesize delegate;
@synthesize imageV;
@synthesize image;
- (IBAction)done:(id)sender{
mapInfo *newEntry = [[mapInfo alloc] init];
if (self.nameT.text.length < 1) {
[self.nameT becomeFirstResponder];
return;
}
if (self.locationT.text.length < 1){
[self.locationT becomeFirstResponder];
return;
}
if (self.descriptionT.text.length < 1){
[self.descriptionT becomeFirstResponder];
return;
}
if (self.image == nil){
[[[UIAlertView alloc] initWithTitle:@"Attention" message:@"Please select a photo as the map from your photo library" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
[self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
return;
}
newEntry.name = self.nameT.text;
newEntry.location = self.locationT.text;
newEntry.description = self.descriptionT.text;
newEntry.eId = arc4random()%10000;
newEntry.map = self.image;
[self.delegate NewTableDone:self entry:newEntry];
NSLog(@"NewTableViewController call done.");
}
- (void) dealloc
{
[nameT release];
[locationT release];
[descriptionT release];
[imageV release];
[image release];
[delegate release];
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.image = nil;
ipC = [[UIImagePickerController alloc] init];
pvC = [[TTThumbsViewController alloc] init];
pvC.delegate = self;
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
pvC.photoSource = [[PhotoSource alloc] initWithDirection:[path stringByAppendingPathComponent:@"WifiCap"]];
}
- (void)viewDidUnload{
[super viewDidUnload];
[ipC release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
[self.nameT becomeFirstResponder];
break;
case 1:
[self.locationT becomeFirstResponder];
break;
case 2:
[self.descriptionT becomeFirstResponder];
break;
default:
break;
}
}
else if(indexPath.section == 1){
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Please choose a photo source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Photo Library" otherButtonTitles:@"Camera", @"App's Document", nil];
[as showInView:self.view];
[as release];
[tableView cellForRowAtIndexPath:indexPath].selected = NO;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 1){
if(self.image != nil){
return 100;
}
}
return 44;
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.image.size.height < self.image.size.width*0.8){
CGSize size = self.image.size;
CGRect rect = CGRectMake((size.width - size.height*0.8)/2, 0, size.height*0.8, size.height);
self.imageV.image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([self.image CGImage], rect)];
}
else
self.imageV.image = image;
[self.tableView reloadData];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated:YES];
}
#pragma mark - UIActionsheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case 0:
ipC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
ipC.delegate = self;
[self presentModalViewController:ipC animated:YES];
break;
case 1:
ipC.sourceType = UIImagePickerControllerSourceTypeCamera;
ipC.delegate = self;
[self presentModalViewController:ipC animated:YES];
break;
case 2:
[self.navigationController pushViewController:pvC animated:YES];
break;
default:
break;
}
}
#pragma mark - TTThumbsViewController
- (void)thumbsViewController:(TTThumbsViewController *)controller didSelectPhoto:(id<TTPhoto>)photo{
Photo *tmp = (Photo*)photo;
self.image = [UIImage imageWithContentsOfFile:tmp.path];
if(self.image.size.height < self.image.size.width*0.8){
CGSize size = self.image.size;
CGRect rect = CGRectMake((size.width - size.height*0.8)/2, 0, size.height*0.8, size.height);
self.imageV.image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([self.image CGImage], rect)];
}
else
self.imageV.image = image;
[self.tableView reloadData];
[self.navigationController popViewControllerAnimated:YES];
}
@end