Description: implements a menu for selecting chart type.
#import "MenuTableController.h" #import "SelectedCellAction.h" @interface Menu : UIViewController<SelectedCellAction> { MenuTableController *menuTableController; UIToolbar *bar; id<SelectedCellAction> _delegate; } - (UIToolbar *) createToolBar; - (void ) back; @property (nonatomic,assign) id<SelectedCellAction> delegate; @end
#import "Menu.h" @implementation Menu @synthesize delegate = _delegate; - (id)init { self = [super init]; if (self) { self.view.frame = CGRectMake(50, 50, 300, 500); [self.view setBackgroundColor:[UIColor blackColor]]; bar = [self createToolBar]; [self.view addSubview:bar]; menuTableController = [[MenuTableController alloc] initWithStyle:UITableViewStylePlain]; menuTableController.tableView.frame = CGRectMake(2, 40, 296, 458); menuTableController.delegate = self; [self.view addSubview:menuTableController.tableView]; } return self; } - (void )selectedItemWithIndex:(NSInteger)index { if(_delegate) { [_delegate selectedItemWithIndex:index]; // Pass selected cell index to delegate [self back]; // Menu close function } } - (UIToolbar *)createToolBar { UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; [toolBar setBarStyle:UIBarStyleBlack]; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:self action:@selector(back)]; toolBar.items = [NSArray arrayWithObjects:backButton, nil ]; return [toolBar autorelease]; } - (void ) back { [self.view removeFromSuperview]; } - (void )didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - View lifecycle - (void )viewDidLoad { [super viewDidLoad]; } - (void )viewDidUnload { [super viewDidUnload]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } @end
See also: