Redauser
Redauser

Reputation: 159

How to construct a menu with a drill down table pointing to other ViewControllers in Xcode

I'm new to Objective-C, I like it, I'm developping a free application for the local firefighters. The app does nothing really hard, but I have a big problem with the main menu: I have already created a table content all the section of my application, I am trying to implement the drill down method by means I can access to other ViewControllers, but I really don't know how to do it, I googled a lot but I've only found fragmentary documentation referenced to old versions of Xcode. I'm using version 4.5.2 and the storyboard.

enter image description here

Here is the menu.h

    #import <UIKit/UIKit.h>

    @interface Menu : UITableViewController
    @property (nonatomic, retain) NSMutableArray *listaMenu; //questo sarà il mio array contentente le varie opzioni della tabella

    @end

And the menu.m

#import "Menu.h"
#import "News.h"

@interface Menu ()

@end

@implementation Menu

@synthesize listaMenu; //creo i metodi getter e setter

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"Menu";

    //Elementi da visualizzare nella tabella
    listaMenu = [[NSMutableArray alloc] initWithObjects: @"News", @"Memebri", @"Calendario", @"Interventi", @"Galleria", @"Mezzi", @"Reclutamento",  nil];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //funzione in cui va inserito il numero di righe da visualizzare

    return [listaMenu count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = nil;

    cell =[tableView dequeueReusableCellWithIdentifier:@"PlistCell"];

    if(cell == nil){

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PlistCell"];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }

    cell.textLabel.text = [listaMenu objectAtIndex:indexPath.row];

    return cell;

}


// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath //Rende gli oggetti NON editabili
{
    // Return NO if you do not want the specified item to be editable.
    //return YES;
    return NO;

}




#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.

     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];

}

@end

I hope my problem is well explained.

Thank you very much!

Upvotes: 0

Views: 226

Answers (1)

ikuramedia
ikuramedia

Reputation: 6058

You need to read up about UISegue - this is the object that handles transitions from one UIViewController to another controller. In Interface Builder you can Ctrl-Drag to create a Segue between, say a UIButton and the desired UIViewController. This is the simplest usage of segues.

If you need to pass data to the destination UIViewController then you'll need to implement the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method. Within this method you can get the segue.destinationViewController and then send it whatever data you need. N.B. The destination view controller's view has not loaded yet, so if you're trying to customise UIViews directly, then they won't exist. You can fudge it by doing [segue.destinationViewController view] to get going, although it would be better to configure non-UI properties and have the view controller itself do any necessary customisation in viewDidLoad.

Upvotes: 1

Related Questions