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