00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "MoodleResultViewController.h"
00010 #import "MoodleExampleAppDelegate.h"
00011 #import "Moodle.h"
00012
00013 @implementation MoodleResultViewController
00014
00015 @synthesize description;
00016
00017 - (id) initWithTitle:(NSString*) aTitle andDescription:(NSString*) aDescription
00018 {
00019 self = [super initWithStyle:UITableViewStylePlain];
00020
00021 if (nil != self) {
00022
00023 views = [[NSMutableArray alloc] init];
00024
00025
00026
00027
00028 UIBarButtonItem *barItem = [[UIBarButtonItem alloc] init];
00029 barItem.title = @"Back";
00030 self.navigationItem.backBarButtonItem = barItem;
00031 [barItem release];
00032
00033
00034 self.title = aTitle;
00035 self.description = aDescription;
00036
00037 }
00038
00039 return self;
00040 }
00041
00042 - (void)viewDidLoad
00043 {
00044 [super viewDidLoad];
00045
00046 [self customize];
00047 }
00048
00049 - (void)viewWillAppear:(BOOL)animated
00050 {
00051 [super viewWillAppear:animated];
00052 moodle = [MoodleExampleAppDelegate instance].moodle;
00053 [self execute];
00054
00055 }
00056
00057 - (void) customize {}
00058 - (void) execute {}
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 - (void)didReceiveMemoryWarning {
00108
00109 [super didReceiveMemoryWarning];
00110
00111
00112 }
00113
00114 - (void)viewDidUnload {
00115
00116
00117 }
00118
00119
00120 #pragma mark Table view methods
00121
00122 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
00123 return 1;
00124 }
00125
00126
00127 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
00128 {
00129 return [views count];
00130 }
00131
00132
00133 - (UITableViewCell *)tableView:(UITableView *)tableView
00134 cellForRowAtIndexPath:(NSIndexPath *)indexPath
00135 {
00136
00137 static NSString *CellIdentifier = @"Cell";
00138
00139 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
00140 if (cell == nil) {
00141 cell = [[[UITableViewCell alloc]
00142 initWithStyle:UITableViewCellStyleSubtitle
00143 reuseIdentifier:CellIdentifier]
00144 autorelease];
00145 }
00146
00147
00148 if (nil != [[views objectAtIndex:indexPath.row] valueForKey:@"controller"]) {
00149 cell.selectionStyle = UITableViewCellSelectionStyleGray;
00150 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
00151 }
00152 else {
00153 cell.selectionStyle = UITableViewCellSelectionStyleNone;
00154 }
00155 cell.textLabel.text = [[views objectAtIndex:indexPath.row] valueForKey:@"title"];
00156 cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
00157 cell.detailTextLabel.text = [[views objectAtIndex:indexPath.row] valueForKey:@"description"];
00158 cell.detailTextLabel.font = [UIFont systemFontOfSize:11.0];
00159
00160 return cell;
00161 }
00162
00163
00164
00165 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
00166 MoodleResultViewController *controller = [[views objectAtIndex:indexPath.row]
00167 objectForKey:@"controller"];
00168 if (nil != controller) {
00169 [self.navigationController pushViewController:controller
00170 animated:YES];
00171 }
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 - (void) failed:(RMResponse*) response error:(NSError*) error
00217 {
00218
00219 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
00220 message:[error localizedFailureReason]
00221 delegate:self
00222 cancelButtonTitle:@"OK"
00223 otherButtonTitles:nil];
00224 [alert show];
00225 [alert release];
00226 }
00227
00228 - (void)dealloc {
00229 self.description = nil;
00230 [views release];
00231 [super dealloc];
00232 }
00233
00234
00235 @end
00236