3305
|
1 |
//
|
|
2 |
// DetailViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 27/03/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "DetailViewController.h"
|
3312
|
10 |
#import "SDL_uikitappdelegate.h"
|
3305
|
11 |
#import "TeamSettingsViewController.h"
|
3312
|
12 |
#import "GeneralSettingsViewController.h"
|
3335
|
13 |
#import "CommodityFunctions.h"
|
3305
|
14 |
|
|
15 |
@implementation DetailViewController
|
|
16 |
@synthesize popoverController, controllers;
|
|
17 |
|
|
18 |
|
3335
|
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
20 |
return rotationManager(interfaceOrientation);
|
|
21 |
}
|
|
22 |
|
3305
|
23 |
- (void)viewDidLoad {
|
|
24 |
self.title = NSLocalizedString(@"Settings",@"");
|
|
25 |
|
3316
|
26 |
// allocate controllers and store them into the array
|
3305
|
27 |
NSMutableArray *array= [[NSMutableArray alloc] init];
|
|
28 |
|
3312
|
29 |
GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
|
|
30 |
initWithStyle:UITableViewStyleGrouped];
|
|
31 |
generalSettingsViewController.title = NSLocalizedString(@"General",@"");
|
|
32 |
[array addObject:generalSettingsViewController];
|
|
33 |
[generalSettingsViewController release];
|
|
34 |
|
3305
|
35 |
TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc]
|
|
36 |
initWithStyle:UITableViewStyleGrouped];
|
|
37 |
teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
|
|
38 |
[array addObject:teamSettingsViewController];
|
|
39 |
[teamSettingsViewController release];
|
|
40 |
|
|
41 |
self.controllers = array;
|
|
42 |
[array release];
|
3316
|
43 |
|
|
44 |
// on ipad make the general setting the first view, on iphone add the "Done" button on top left
|
|
45 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
46 |
UITableViewController *nextController = [self.controllers objectAtIndex:0];
|
|
47 |
nextController.navigationItem.hidesBackButton = YES;
|
|
48 |
[self.navigationController pushViewController:nextController animated:NO];
|
|
49 |
} else {
|
|
50 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 target:self action:@selector(dismissSplitView)];
|
|
51 |
}
|
|
52 |
|
3305
|
53 |
[super viewDidLoad];
|
|
54 |
}
|
|
55 |
|
|
56 |
- (void)didReceiveMemoryWarning {
|
|
57 |
// Releases the view if it doesn't have a superview.
|
|
58 |
[super didReceiveMemoryWarning];
|
|
59 |
// Release any cached data, images, etc that aren't in use.
|
|
60 |
}
|
|
61 |
|
|
62 |
- (void)viewDidUnload {
|
|
63 |
self.controllers = nil;
|
|
64 |
self.popoverController = nil;
|
|
65 |
[super viewDidUnload];
|
|
66 |
}
|
|
67 |
|
|
68 |
- (void)dealloc {
|
|
69 |
[controllers release];
|
|
70 |
[popoverController release];
|
|
71 |
[super dealloc];
|
|
72 |
}
|
|
73 |
|
|
74 |
#pragma mark -
|
|
75 |
#pragma mark Table view data source
|
|
76 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
77 |
return 1;
|
|
78 |
}
|
|
79 |
|
|
80 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
81 |
return [controllers count];
|
|
82 |
}
|
|
83 |
|
|
84 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
85 |
static NSString *CellIdentifier = @"Cell";
|
|
86 |
|
|
87 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
88 |
if (cell == nil) {
|
|
89 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
90 |
reuseIdentifier:CellIdentifier] autorelease];
|
|
91 |
}
|
|
92 |
|
|
93 |
NSInteger row = [indexPath row];
|
|
94 |
UITableViewController *controller = [controllers objectAtIndex:row];
|
|
95 |
|
|
96 |
cell.textLabel.text = controller.title;
|
|
97 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
|
|
98 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
99 |
|
|
100 |
return cell;
|
|
101 |
}
|
|
102 |
|
|
103 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
104 |
NSInteger row = [indexPath row];
|
|
105 |
UITableViewController *nextController = [self.controllers objectAtIndex:row];
|
|
106 |
[self.navigationController pushViewController:nextController animated:YES];
|
|
107 |
}
|
|
108 |
|
|
109 |
/*
|
|
110 |
#pragma mark -
|
|
111 |
#pragma mark Managing the popover controller
|
|
112 |
// When setting the detail item, update the view and dismiss the popover controller if it's showing.
|
|
113 |
-(void) setDetailItem:(id) newDetailItem {
|
|
114 |
if (detailItem != newDetailItem) {
|
|
115 |
[detailItem release];
|
|
116 |
detailItem = [newDetailItem retain];
|
|
117 |
|
|
118 |
// Update the view.
|
|
119 |
// navigationBar.topItem.title = (NSString*) detailItem;
|
|
120 |
|
|
121 |
//test.text=(NSString*) detailItem;
|
|
122 |
}
|
|
123 |
|
|
124 |
// if (popoverController != nil) {
|
|
125 |
// [popoverController dismissPopoverAnimated:YES];
|
|
126 |
// }
|
|
127 |
}
|
|
128 |
*/
|
|
129 |
|
|
130 |
#pragma mark -
|
|
131 |
#pragma mark Split view support
|
|
132 |
#ifdef __IPHONE_3_2
|
3335
|
133 |
-(void) splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
|
3305
|
134 |
barButtonItem.title = @"Master List";
|
3335
|
135 |
[self.navigationController.navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
|
3305
|
136 |
self.popoverController = pc;
|
|
137 |
}
|
|
138 |
|
|
139 |
// Called when the view is shown again in the split view, invalidating the button and popover controller.
|
|
140 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
|
3335
|
141 |
[self.navigationController.navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
|
3305
|
142 |
self.popoverController = nil;
|
|
143 |
}
|
|
144 |
#endif
|
3316
|
145 |
|
3305
|
146 |
-(IBAction) dismissSplitView {
|
|
147 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
148 |
}
|
|
149 |
|
|
150 |
@end
|