-
Notifications
You must be signed in to change notification settings - Fork 2
/
DetailsViewController.m
executable file
·125 lines (96 loc) · 3.54 KB
/
DetailsViewController.m
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
//
// DetailsViewController.m
// searchbar
//
// Created by mmai on 11/27/13.
// Copyright (c) 2013 mmai. All rights reserved.
//
#import "DetailsViewController.h"
@interface DetailsViewController ()
@end
@implementation DetailsViewController
@synthesize delegate;
@synthesize bug;
@synthesize scrollView;
@synthesize orderLabel;
@synthesize invertebrateImage;
@synthesize nameOfBug;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[orderLabel setNumberOfLines:0];
[orderLabel sizeToFit];
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width, orderLabel.bounds.size.height+400)];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableString *details = [[NSMutableString alloc] init];
delegate = (macroinvAppDelegate *) [[UIApplication sharedApplication] delegate]; // to refer to AppDelegate methods
NSString *s = [bug.imageFile stringByReplacingOccurrencesOfString:@"File:" withString:@""];
NSArray * se = [s componentsSeparatedByString:@"."];
UIImage *image;
if ([se count] > 1) {
image = [delegate.webData loadImage:[se objectAtIndex:0] ofType:[se objectAtIndex:1]];
} else {
image = nil;
}
// LOOK HERE TO TEST DetailView
// Uncomment the line below to test
// image = nil;
if(image != nil) { // Show real image
[invertebrateImage setImage:image];
} else if (delegate.webData.downloadInProgress == TRUE) { // Show downloading placeholder
[invertebrateImage setImage:[UIImage imageNamed:@"placeholder-queued.png"]];
NSLog(@"Image is queued for download: %@", bug.imageFile);
} else { // Show failure placeholder
[invertebrateImage setImage:[UIImage imageNamed:@"placeholder-unavailable.png"]];
NSLog(@"Failed to load image: %@", bug.imageFile);
}
// Conditionally add attributes to the view if and only if they're set
// if order is not there, dont show orderlabel and ordertopic
if ([bug.order length ] > 3){
NSString *topic = @"Order: ";
NSString *value = bug.order;
[details appendString:[topic stringByAppendingString:value]];
}
if ([bug.family length ] > 3){
NSString *topic = @"\nFamily: ";
NSString *value = bug.family;
[details appendString:[topic stringByAppendingString:value]];
}
if ([bug.genus length ] > 3){
NSString *topic = @"\nGenus: ";
NSString *value = bug.genus;
[details appendString:[topic stringByAppendingString:value]];
}
if ([bug.commonName length ] > 3){
NSString *topic = @"\nCommon Name: ";
NSString *value = bug.commonName;
[details appendString:[topic stringByAppendingString:value]];
}
if ([bug.flyName length ] > 3){
NSString *topic = @"\nFly Name: ";
NSString *value = bug.flyName;
[details appendString:[topic stringByAppendingString:value]];
}
if ([bug.description length ] > 3){
NSString *topic = @"\nDescription: \n";
NSString *value = bug.text;
[details appendString:[topic stringByAppendingString:value]];
}
orderLabel.text = details;
nameOfBug.text = bug.name;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end