2014-10-10 43 views
0

我試着做一個細節列表,但我不能這樣做,我不明白爲什麼。UITableView細節轉換

是故事板,故事板連接好。細節只有一個tableView和View控制器。

我想在一個單元來推動並轉到詳細畫面,並在細節類我2個propertys但是當我推在一個單元中,應用程序崩潰和我有一個例外:

終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「不能在包中加載NIB:‘一個NSBundle(加載)’名爲'GasolDetalleVCViewController」 ***第一擲調用堆棧:

的類是:

表控制器.h:

#import <UIKit/UIKit.h> 
#import "GasolDetalleVCViewController.h" 
#import "DetallesGasol.h" 

@interface GasolTVCTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate> 
{ 
    NSMutableArray *arrayNombrePrecio; 
    NSInteger celdaPulsada; 
} 
@end 

表控制器的.m:

#import "GasolTVCTableViewController.h" 

@interface GasolTVCTableViewController() 

@end 

@implementation GasolTVCTableViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    arrayNombrePrecio = [NSMutableArray arrayWithCapacity:10]; 

    DetallesGasol *textoCelda0 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda1 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda2 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda3 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda4 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda5 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda6 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda7 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda8 = [[DetallesGasol alloc]init]; 
    DetallesGasol *textoCelda9 = [[DetallesGasol alloc]init]; 

    textoCelda0.nombre = @"Autogas Alcorcon"; 
    textoCelda0.precio = 0.71; 
    textoCelda0.latitud = 40.3427359; 
    textoCelda0.longitud = -3.8053231000000096; 
    [arrayNombrePrecio addObject:textoCelda0]; 

    textoCelda1.nombre = @"Autogas Atalayuela Vallecas"; 
    textoCelda1.precio = 0.72; 
    textoCelda1.latitud = 40.3707274; 
    textoCelda1.longitud = -3.643952000000013; 
    [arrayNombrePrecio addObject:textoCelda1]; 

    textoCelda2.nombre = @"GLP Santa Eugenia"; 
    textoCelda2.precio = 0.702; 
    textoCelda2.latitud = 40.3831964; 
    textoCelda2.longitud = -3.6279809000000114; 
    [arrayNombrePrecio addObject:textoCelda3]; 

    textoCelda3.nombre = @"Autogas Hispanidad"; 
    textoCelda3.precio = 0.73; 
    textoCelda3.latitud = 40.4678932; 
    textoCelda3.longitud = -3.57114660000002; 
    [arrayNombrePrecio addObject:textoCelda3]; 

    textoCelda4.nombre = @"Autogas Mendez Alvaro"; 
    textoCelda4.precio = 0.72; 
    textoCelda4.latitud = 40.3911409; 
    textoCelda4.longitud = -3.6750798000000486; 
    [arrayNombrePrecio addObject:textoCelda4]; 

    textoCelda5.nombre = @"Autogas Hipódromo"; 
    textoCelda5.precio = 0.70; 
    textoCelda5.latitud = 40.4635268; 
    textoCelda5.longitud = -3.7577165999999806; 
    [arrayNombrePrecio addObject:textoCelda5]; 

    textoCelda6.nombre = @"Autogas Las Tablas"; 
    textoCelda6.precio = 0.71; 
    textoCelda6.latitud = 40.5074619; 
    textoCelda6.longitud = -3.6695012000000133; 
    [arrayNombrePrecio addObject:textoCelda6]; 

    textoCelda7.nombre = @"GLP Alcorcon"; 
    textoCelda7.precio = 0.73; 
    textoCelda7.latitud = 40.3440681; 
    textoCelda7.longitud = -3.838870799999995; 
    [arrayNombrePrecio addObject:textoCelda7]; 

    textoCelda8.nombre = @"Autogas Las Rozas"; 
    textoCelda8.precio = 0.72; 
    textoCelda8.latitud = 40.50090272885034; 
    textoCelda8.longitud = -3.8722419196654982; 
    [arrayNombrePrecio addObject:textoCelda8]; 

    textoCelda9.nombre = @"Autogas Pinto"; 
    textoCelda9.precio = 0.72; 
    textoCelda9.latitud = 40.2550693; 
    textoCelda9.longitud = -3.69782639999994; 
    [arrayNombrePrecio addObject:textoCelda9]; 

} 

- (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 { 
    // Return the number of rows in the section. 
    return 10; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"celda"]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"celda"]; 
    } 

    DetallesGasol *detalleAux = [arrayNombrePrecio objectAtIndex:indexPath.row]; 
    NSString *aux = [NSString stringWithFormat:@"%.3f", detalleAux.precio]; 

    cell.textLabel.text = detalleAux.nombre; 
    cell.detailTextLabel.text = aux; 

    cell.textLabel.minimumFontSize = 12; 
    cell.detailTextLabel.minimumFontSize = 12; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    GasolDetalleVCViewController *detailVC = [[GasolDetalleVCViewController alloc]initWithNibName:@"GasolDetalleVCViewController" bundle:nil]; 

    DetallesGasol *detAux = [arrayNombrePrecio objectAtIndex:indexPath.row]; 
    NSString *strAuxLat = [NSString stringWithFormat:@"%f", detAux.latitud]; 
    NSString *strAuxLon = [NSString stringWithFormat:@"%f", detAux.longitud]; 

    detailVC.latitud = strAuxLat; 
    detailVC.longitud = strAuxLon; 

    [self.navigationController pushViewController:detailVC animated:YES]; 
} 

//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
// // Get the new view controller using [segue destinationViewController]. 
// // Pass the selected object to the new view controller. 
//  
//// GasolDetalleVCViewController *gasol = segue.destinationViewController; 
//// gasol.detalle = [arrayNombrePrecio objectAtIndex:celdaPulsada]; 
//  
//} 

@end 

Array類對象的.h:

#import <Foundation/Foundation.h> 

@interface DetallesGasol : NSObject 

@property (strong, nonatomic) NSString *nombre; 
@property (assign) CGFloat precio; 
@property (assign) CGFloat latitud; 
@property (assign) CGFloat longitud; 

@end 

Array類對象的.m:

#import "DetallesGasol.h" 

@implementation DetallesGasol 

@end 

細節類控制器的.h:

#import <UIKit/UIKit.h> 

@interface GasolDetalleVCViewController : UIViewController 

@property (strong, nonatomic) NSString *latitud; 
@property (strong, nonatomic) NSString *longitud; 

@end 

細節類控制器的.m:

#import "GasolDetalleVCViewController.h" 

@interface GasolDetalleVCViewController() 

@end 

@implementation GasolDetalleVCViewController 
@synthesize latitud, longitud; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    NSLog(@"Entra en viewDidLoad de GasolDetalleViewController"); 
    NSLog(@"latitud: %@", latitud); 
    NSLog(@"longitud: %@", latitud); 
} 

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

非常感謝

+0

您已使CustemClass – 2014-10-10 10:48:04

回答

0

當您重命名以外的XCode一些文件,這個錯誤可以occure。爲了解決它,你可以從你的項目中刪除文件(右鍵單擊 - 刪除和「刪除參考」)您重新導入項目中的文件,一切都會好的!

+0

此解決方案是我嘗試的第一個解決方案,但在這種情況下,不是解決方案。感謝您的關注! – krayan 2014-10-10 11:27:01