Pregunta

He creado una barra de aplicaciones Tab, eliminado el defecto FirstView y SecondView y añadido los siguientes dos ViewControllers:

  1. JustAnotherView (que es simplemente una UIViewController con un interior UIView)
  2. MyListOfItems (que es un UIViewController con un interior TableView)

Tengo un tercio ViewController llama ListOfItemsDetailViewController con un interior UIView que se supone que se llamará cuando el usuario toca una de las celdas TableView.

La aplicación compila sin ningún problema. Puedo tocar los dos botones barra de pestañas y la visión correcta aparecerá.

PROBLEMA: Cuando hago clic en una celda TableView, el código para cambiar al detalle se ejecuta Vista (sin que se caiga o error), pero la vista no se muestra nunca.

Esta es una captura de pantalla de la aplicación y el depurador con un NSLog que muestra lo hizo más allá de la pushViewController sin que se caiga:

http://clip2net.com/clip/m52549/thumb640 /1281588813-9c0ba-161kb.jpg

Este es el código.

MyListOfItemsViewController.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ListOfItemsDetailViewController.h";

@interface MyListOfItemsViewController : UIViewController {
    ListOfItemsDetailViewController *listOfItemsDetailViewController;
}

@property (nonatomic, retain) ListOfItemsDetailViewController *listOfItemsDetailViewController;


@end

Aquí está el archivo MyListOfItemsViewController.m:

#import "MyListOfItemsViewController.h"
@implementation MyListOfItemsViewController
@synthesize listOfItemsDetailViewController;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.title = @"My List Of Items";
    NSLog(@"My List Of Items Did Load");
}

#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    NSString *cellMessage;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cellMessage = [NSString stringWithFormat:@"indexPath: %d",indexPath.row];       
    cell.textLabel.text = cellMessage;
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ListOfItemsDetailViewController *vcListOfItemsDetail = [[ListOfItemsDetailViewController alloc] 
                                    initWithNibName:@"ListOfItemsDetail" bundle:[NSBundle mainBundle]];
    self.listOfItemsDetailViewController = vcListOfItemsDetail;
    [vcListOfItemsDetail release];
    [self.navigationController pushViewController:self.listOfItemsDetailViewController animated:YES];

    NSLog(@"Did Execute didSelectRowAtIndexPath WITHOUT Crashing or Error.");

}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
    NSLog(@"My List Of Items View Did Unload");
}


- (void)dealloc {
    [super dealloc];
}



@end

Por favor, ayuda. Será muy apreciada !!!

He estado conduciendo yo loco tratando de conseguir la navegación básica en la plataforma iOS.

Además, perdón la pregunta laico, sé que la mayoría de ustedes ya entienden cómo hacer esto.

Gracias de antemano. Jaosn

¿Fue útil?

Solución

En tableView:didSelectRowAtIndexPath: se hace referencia a un navigationController por self.navigationController, que probablemente no existe. Usted tiene que utilizar un UINavigationController como controlador de un punto de vista en que TabView y la RootViewController de ese navigationController debe ser MyListOfItemsViewController.

Tenga en cuenta que se necesita un UINavigationController para su vista de detalle a presionarlo para self.navigationController es sólo una manera de recuperar uno, que ha sido creado y se inserta en la jerarquía antes.

Otros consejos

En lugar de hacer viewcontroller de la segunda pestaña a ser un tableviewcontroller, lo convierten en un UINavigationController y establecer RootViewController del NavController como "MyListOfItems". Una vez hecho esto, usted tendrá acceso a la propiedad navigationController en su viewcontroller y puede usar la inserción y el pop.

O si usted no quiere hacer esto, el único camino que queda sería animado entre los puntos de vista mediante programación (es decir, eliminar una vista y añadir el otro o añadir otro punto de vista en la parte superior de la vista actual)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top