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