View difference between Paste ID: iFKb6BWQ and
SHOW: | | - or go back to the newest paste.
1-
1+
@interface SecondViewController : UIViewController {
2
	
3
	NSMutableArray *short_desc;
4
}
5
6
- (IBAction)search:(id)sender;
7
8
@end
9
10
- (IBAction)search:(id)sender {
11
	UIViewController *artikel = [[UIViewController alloc] init];
12
	artikel.title = @"Artikel";
13
	artikel.view = resultView;
14
	
15
	BOOL pushViewController = [self xmlRequest];
16
17
	if (!pushViewController) {
18
		UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Hinweis" message:@"Für Ihre Suchanfrage wurden keine passenden Einträge in der Datenbank gefunden" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
19
		[errorAlert show];   
20
	}
21
	else {
22
		[self.navigationController pushViewController:artikel animated:YES];
23
		[tableView reloadData];
24
25
	}
26
27
}
28
29
30
- (BOOL)xmlRequest {
31
	NSString *p1, *p2, *p3, *p4, *p5, *p6;
32
	p1 = [NSString stringWithFormat:@"%d", ([pickerView selectedRowInComponent:0] + 1)];
33
	p2 = [NSString stringWithFormat:@"%d", ([pickerView selectedRowInComponent:1] + 2010)];
34
	
35
	switch ([pickerView selectedRowInComponent:2]) {
36
		case 0:
37
			p3 = @"Deutschland";
38
			break;
39
		case 1:
40
			p3 = @"Österreich";
41
			break;
42
		case 2:
43
			p3 = @"Schweiz";
44
			break;
45
		default:
46
			break;
47
	}
48
	
49
	p4 = cityField.text;
50
	p5 = branchField.text;
51
	p6 = messeNameField.text;
52
	
53
	NSString *url = [NSString stringWithFormat:A4M_XML_SERVICE, p1, p2, p3, p4, p5, p6];
54
	NSString *xmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:url]];
55
	NSString *xmlStringUTF8 = [NSString stringWithUTF8String:[xmlString UTF8String]];
56
	
57
	CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithXMLString:xmlStringUTF8 options:0 error:nil];
58
	
59
	NSString *result;
60
	NSString *error;
61
	short_desc = [NSMutableArray arrayWithCapacity:10];
62
	name = [NSMutableArray arrayWithCapacity:10];
63
	location = [NSMutableArray arrayWithCapacity:10];
64
	startDate = [NSMutableArray arrayWithCapacity:10];
65
	
66
	//Check for nil:
67
	NSArray *nodes = [xmlDoc nodesForXPath:@"/xml/items" error:nil];
68
	
69
	if (nodes != nil && [nodes count] >= 1) {
70
		for (int i = 0; i < [nodes count]; i++) {
71
			CXMLElement *resultElement = [nodes objectAtIndex:i];
72
			error = [[[[resultElement attributeForName:@"count"] stringValue] copy] autorelease];		
73
		}
74
	}
75
76
	if ([error intValue] == 0) {
77
		return NO;
78
	}
79
	
80
	//Short-Description:
81
	nodes = [xmlDoc nodesForXPath:@"/xml/items/item/short_desc" error:nil];
82
	
83
	if (nodes != nil && [nodes count] >= 1) {
84
		for (int i = 0; i < [nodes count]; i++) {
85
			CXMLElement *resultElement = [nodes objectAtIndex:i];
86
			result = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease];		
87
			[short_desc addObject:result];
88
		}
89
	}
90
	
91
	//Name:
92
	nodes = [xmlDoc nodesForXPath:@"/xml/items/item/name" error:nil];
93
	
94
	if (nodes != nil && [nodes count] >= 1) {
95
		for (int i = 0; i < [nodes count]; i++) {
96
			CXMLElement *resultElement = [nodes objectAtIndex:i];
97
			result = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease];		
98
			[name addObject:result];
99
		}
100
	}
101
	
102
	//Location:
103
	nodes = [xmlDoc nodesForXPath:@"/xml/items/item/location" error:nil];
104
	
105
	if (nodes != nil && [nodes count] >= 1) {
106
		for (int i = 0; i < [nodes count]; i++) {
107
			CXMLElement *resultElement = [nodes objectAtIndex:i];
108
			result = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease];		
109
			[location addObject:result];
110
		}
111
	}
112
	
113
	//Date:
114
	nodes = [xmlDoc nodesForXPath:@"/xml/items/item/date" error:nil];
115
	
116
	if (nodes != nil && [nodes count] >= 1) {
117
		for (int i = 0; i < [nodes count]; i++) {
118
			CXMLElement *resultElement = [nodes objectAtIndex:i];
119
			result = [[[[resultElement attributeForName:@"start"] stringValue] copy] autorelease];		
120
			[startDate addObject:result];
121
		}
122
	}
123
	
124
	NSLog([name objectAtIndex:0]);
125
	NSLog([location objectAtIndex:0]);
126
	NSLog([startDate objectAtIndex:0]);
127
	NSLog([short_desc objectAtIndex:0]);
128
	
129
	return YES;
130
}
131
132
133
//TableView:
134
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
135
	return 1;
136
}
137
138
139
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
140
	return [name count];
141
}
142
143
144
#define ASYNC_IMAGE_TAG 9999
145
#define LABEL_TAG_1 8888
146
#define LABEL_TAG_2 7777
147
148
149
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
150
	
151
	static NSString *CellIdentifier = @"Cell";
152
	
153
	NSInteger row = [indexPath row];
154
	
155
	CGRect tRect3 = CGRectMake(0.0f, 0.0f, 420.0f, 60.0f);
156
    
157
	AsyncImageView *asyncImageView = nil;
158
    UILabel *labelDate = nil;
159
	UILabel *labelTitle = nil;
160
	UIImageView *image = nil;
161
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
162
    if (cell == nil) {
163
        cell = [[[UITableViewCell alloc] initWithFrame:tRect3 reuseIdentifier:CellIdentifier] autorelease];
164
		[[[cell subviews] objectAtIndex:0] setTag:111];
165
		
166
		//Datum-Label:
167
		[labelDate setTextAlignment:UITextAlignmentLeft];
168
		CGRect tRect1 = CGRectMake(65.0f, 3.0f, 215.0f, 15.0f);
169
        labelDate = [[[UILabel alloc] initWithFrame:tRect1] autorelease];
170
        labelDate.tag = LABEL_TAG_1;
171
		
172
		//Titel-Label:
173
		[labelTitle setTextAlignment:UITextAlignmentLeft];
174
		CGRect tRect2 = CGRectMake(65.0f, 15.0f, 215.0f, 40.0f);
175
		labelTitle = [[[UILabel alloc] initWithFrame:tRect2] autorelease];
176
		labelTitle.tag = LABEL_TAG_2;
177
		
178
		//UITableViewCellAccessoryDisclosureIndicator
179
		CGRect tRect4 = CGRectMake(300.0f, 0.0f, 10.0f, 60.0f);
180
		image = [[[UIImageView alloc] initWithFrame:tRect4] autorelease];
181
		UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"disclosure" ofType:@"png"]];
182
		[image setImage:img];
183
		
184
		
185
		
186
        [cell.contentView addSubview:labelDate];
187
		[cell.contentView addSubview:labelTitle];
188
		[cell.contentView addSubview:image];
189
    } else {
190
		labelDate = (UILabel *) [cell.contentView viewWithTag:LABEL_TAG_1];
191
		labelTitle = (UILabel *) [cell.contentView viewWithTag:LABEL_TAG_2];
192
    }
193
	
194
	UIView *cellView = [cell viewWithTag:111];
195
	if (row % 2) {
196
		[cellView setBackgroundColor:[UIColor whiteColor]];
197
	} else {
198
		[cellView setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]];
199
	}
200
    
201
	
202
	
203
	
204
	NSString *date = [short_desc objectAtIndex:0]; //App crashes at this point
205
	
206
	
207
	labelDate.text = date;
208
	labelDate.textColor = [UIColor darkGrayColor];
209
	[labelDate setFont:[UIFont systemFontOfSize:12.0f]];
210
	[labelDate setBackgroundColor:[UIColor clearColor]];
211
	
212
	//labelTitle.text = [name objectAtIndex:0];
213
	labelTitle.lineBreakMode = UILineBreakModeWordWrap;
214
	labelTitle.numberOfLines = 0;
215
	labelTitle.adjustsFontSizeToFitWidth = YES;
216
	[labelTitle setTextAlignment:UITextAlignmentLeft];
217
	[labelTitle setFont: [UIFont systemFontOfSize:16.0f]];
218
	[labelTitle setBackgroundColor: [UIColor clearColor]];
219
	
220
	
221
	
222
    
223
    return cell;
224
}
225
226
227
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
228
{
229
	return 61.0f;
230
}
231
232
233
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
234
	// Navigatoin logic
235
	
236
	int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
237
}
238
239
240
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
241
	// Navigatoin logic
242
	
243
	int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
244
	
245
	[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
246
}