-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyItem.m
More file actions
188 lines (162 loc) · 7.11 KB
/
MyItem.m
File metadata and controls
188 lines (162 loc) · 7.11 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// MyItem.m
// Purge
//
// Created by Ryan Nystrom on 2/18/12.
// Copyright (c) 2012 Topic Design. All rights reserved.
//
#import "MyItem.h"
@implementation MyItem
@synthesize purge = _purge;
@synthesize delegate = _delegate;
@synthesize scrollView = _scrollView;
-(void)dealloc
{
[_scrollView release], _scrollView = nil;
[_purge release], _purge = nil;
[super dealloc];
}
- (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.
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
[[self view] addSubview:view];
[self setScrollView:view];
[view setScrollEnabled:YES];
[view setShowsVerticalScrollIndicator:NO];
[view setAlwaysBounceVertical:YES];
[view setDelegate:self];
[view setBackgroundColor:[UIColor colorWithRed:0.792f green:0.874f blue:0.894f alpha:1]];
[view release], view = nil;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[[self tabBarController] navigationItem] setRightBarButtonItem:nil];
[[self navigationController] setNavigationBarHidden:NO animated:animated];
[MBProgressHUD showHUDAddedTo:[self view] animated:YES];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
int padding = 5;
int runningHeight = padding;
CGSize maxLabelSize = CGSizeMake(320 - 2 * padding, MAXFLOAT);
UIFont *boldFont = [UIFont fontWithName:@"Helvetica-Bold" size:17];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:17];
UIColor *fontColor = [UIColor colorWithRed:0.301f green:0.325f blue:0.431f alpha:1];
PFFile *imageFile = [[self purge] objectForKey:@"image"];
NSData *imageData;
if ( ! [imageFile isDataAvailable]) {
imageData = [imageFile getData];
}
else {
imageData = [[self purge] objectForKey:@"image"];
}
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect frame = CGRectMake(padding, padding, 320 - 2 * padding, 320 - 2 * padding);
[imageView setFrame:frame];
[[self scrollView] addSubview:imageView];
[[imageView layer] setMasksToBounds:YES];
[[imageView layer] setCornerRadius:2.0];
[[imageView layer] setBorderColor:[[UIColor colorWithRed:0.396f green:0.435f blue:0.427f alpha:0.8] CGColor]];
[[imageView layer] setBorderWidth:2.0];
runningHeight += imageView.frame.size.height + padding;
[imageView release], imageView = nil;
UILabel *descriptionTitle = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[descriptionTitle setText:@"Description"];
[descriptionTitle setFont:boldFont];
[[self scrollView] addSubview:descriptionTitle];
runningHeight += descriptionTitle.frame.size.height;
[descriptionTitle setBackgroundColor:[UIColor clearColor]];
[descriptionTitle setTextColor:fontColor];
[descriptionTitle release], descriptionTitle = nil;
UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 40)];
[description setNumberOfLines:0];
[description setLineBreakMode:UILineBreakModeWordWrap];
NSString *dText = [[self purge] objectForKey:@"description"];
CGSize expected = [dText sizeWithFont:font constrainedToSize:maxLabelSize lineBreakMode:UILineBreakModeWordWrap];
frame = [description frame];
frame.size.height = expected.height;
[description setText:dText];
[description setFrame:frame];
[description setTextColor:fontColor];
[[self scrollView] addSubview:description];
runningHeight += description.frame.size.height + padding;
[description setBackgroundColor:[UIColor clearColor]];
[description release], description = nil;
UILabel *priceTitle = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[priceTitle setText:@"Price"];
[priceTitle setFont:boldFont];
[[self scrollView] addSubview:priceTitle];
[priceTitle setTextColor:fontColor];
runningHeight += priceTitle.frame.size.height;
[priceTitle setBackgroundColor:[UIColor clearColor]];
[priceTitle release], priceTitle = nil;
UILabel *price = [[UILabel alloc] initWithFrame:CGRectMake(padding, runningHeight, 320 - 2 * padding, 20)];
[price setNumberOfLines:0];
[price setLineBreakMode:UILineBreakModeWordWrap];
dText = [[self purge] objectForKey:@"price"];
[price setText:dText];
[[self scrollView] addSubview:price];
[price setBackgroundColor:[UIColor clearColor]];
[price setTextColor:fontColor];
runningHeight += price.frame.size.height + padding;
[price release], price = nil;
CGRect buttonFrame = CGRectMake(padding, runningHeight, 320 - 2 * padding, 73);
UIButton *delete = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *deleteImage = [UIImage imageNamed:@"product_button.png"];
[delete setImage:deleteImage forState:UIControlStateNormal];
[delete setTitleEdgeInsets:UIEdgeInsetsMake(10, -320, 5.0, 5.0)];
[[delete titleLabel] setFont:boldFont];
[delete setTitleColor:fontColor forState:UIControlStateNormal];
[delete setTitle:@"Delete" forState:UIControlStateNormal];
[delete addTarget:self action:@selector(onDelete) forControlEvents:UIControlEventTouchUpInside];
[delete setFrame:buttonFrame];
[[self scrollView] addSubview:delete];
runningHeight += delete.frame.size.height + padding;
[[self scrollView] setContentSize:CGSizeMake(320, runningHeight)];
[MBProgressHUD hideHUDForView:[self view] animated:YES];
}
-(void)onDelete
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"Are you sure you want to purge this Purge?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];
[av show];
[av release], av = nil;
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[[self purge] deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
[[self navigationController] popViewControllerAnimated:YES];
[[self delegate] myItemWasDeleted];
}
else {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There was an error processing your request." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[av show];
[av release], av = nil;
}
}];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end