Description: properties and methods for working with menu.
#import "SelectedCellAction.h"
@interface MenuTableController : UITableViewController
{
NSArray *data;
id<SelectedCellAction> _delegate;
}
@property (nonatomic,assign) id<SelectedCellAction> delegate;
@end
#import "MenuTableController.h"
@implementation MenuTableController
@synthesize delegate = _delegate;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
data = [[NSArray arrayWithObjects:@"Column absolute",
@"Column additional",
@"Column percent",
@"Bar absolute",
@"Bar additional",
@"Bar percent",
@"Line absolute",
@"Line additional",
@"Line percent",
@"Area absolute",
@"Area additional",
@"Area percent",
@"Pie",
@"Doughnut", nil] retain];
}
return self;
}
- (void )didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void )viewDidLoad
{
[super viewDidLoad];
}
- (void )viewDidUnload
{
[data release];
[super viewDidUnload];
}
- (void )viewWillAppear:(BOOL )animated
{
[super viewWillAppear:animated];
}
- (void )viewDidAppear:(BOOL )animated
{
[super viewDidAppear:animated];
}
- (void )viewWillDisappear:(BOOL )animated
{
[super viewWillDisappear:animated];
}
- (void )viewDidDisappear:(BOOL )animated
{
[super viewDidDisappear:animated];
}
- (BOOL )shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (void )tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(_delegate)
[_delegate selectedItemWithIndex:indexPath.row]; // Pass selected element number to menu
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setBackgroundColor:[UIColor grayColor]];
cell.textLabel.text = [data objectAtIndex:indexPath.row];
}
cell.textLabel.text = [data objectAtIndex:indexPath.row];
return cell;
}
@end
See also: