私はまだプログラミングの初心者です。私はiOS Devクラスの最終プロジェクトを行っています.それは基本的なアプリを構築することです. 私は数日間これを完了する方法を理解しようとしてきましたが、次々と問題が発生しています。明日が期限なので、今、私は時間に追われています。私のアプリは、シボレー車のリストと各車名の横に写真を表示することになっています。これは、Table View Controller で行われます。私の問題は、セルをクリックしたときにあります。車の情報が空白のラベル。たとえば、「馬力」というラベルがあり、その横に車の実際の馬力が表示されるはずです。実際の馬力を表示する代わりに、空白のラベルが表示されます。不足しているものはありますか?私が使用したコードを皆さんに見せる方法はありますか? 私には「1」の評判しかありません。
どんな助けでも大歓迎です。
これはテーブルビューコントローラーからのものです:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"carTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [_carModels objectAtIndex: indexPath.row];
cell.imageView.image = [UIImage imageNamed:[_carImages objectAtIndex: indexPath.row]];
return cell;
}
これが私のdetailViewController.mです
#import "Chevy2DetailViewController.h"
@interface Chevy2DetailViewController ()
@end
@implementation Chevy2DetailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_modelLabel.text = _currentCarDetail.carModel;
_MSRPLabel.text = _currentCarDetail.carMSRP;
_MPGLabel.text = _currentCarDetail.carMPG;
_airbagLabel.text = _currentCarDetail.carAirbag;
_volumeLabel.text = _currentCarDetail.carVolume;
_horsepowerLabel.text = _currentCarDetail.carHorsepower;
_bigImage.image = [UIImage imageNamed:_currentCarDetail.thumbImageName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
TableViewController.m ファイルは次のとおりです。
//
// Chevy2TableViewController.m
// Chevy2
//
// Created by Anthony Picone on 7/16/13.
// Copyright (c) 2013 Pico. All rights reserved.
//
#import "Chevy2TableViewController.h"
#import "Chevy2TableViewCell.h"
#import "CarDetail.h"
#import "Chevy2DetailViewController.h"
@interface Chevy2TableViewController ()
@end
@implementation Chevy2TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_carModels = @[@"Spark",
@"Sonic",
@"Cruze",
@"Volt",
@"Malibu",
@"Impala",
@"SS",
@"Camaro",
@"Corvette",
@"Equinox",
@"Traverse",
@"Tahoe",
@"Suburban",
@"Avalanche",
@"Silverado"];
_carImages = @[@"spark.png",
@"Sonic.png",
@"Cruze.png",
@"Volt.png",
@"Malibu.png",
@"Impala.png",
@"SS.png",
@"Camaro.png",
@"corvette.png",
@"Equinox.png",
@"Traverse.png",
@"Tahoe.png",
@"Suburban.png",
@"avalanche.png",
@"silverado.png"];
CarDetail *sparkCarDetail = [CarDetail new];
sparkCarDetail.carModel = @"Spark";
sparkCarDetail.carMSRP = @"$12,170";
sparkCarDetail.carMPG = @"38 MPG HWY";
sparkCarDetail.carAirbag= @"10 Airbags";
sparkCarDetail.carVolume = @"31.2 Cubic Feet";
sparkCarDetail.carHorsepower = @"84 HP";
sparkCarDetail.bigImage = @"big_spark.jpg";
CarDetail *sonicCarDetail = [CarDetail new];
sonicCarDetail.carModel = @"Sonic";
sonicCarDetail.carMSRP = @"$14,185";
sonicCarDetail.carMPG = @"40 MPG HWY";
sonicCarDetail.carAirbag= @"10 Airbags";
sonicCarDetail.carVolume = @"14.9 Cubic Feet";
sonicCarDetail.carHorsepower = @"138";
sonicCarDetail.bigImage = @"big_sonic.jpg";
CarDetail *cruzeCarDetail = [CarDetail new];
cruzeCarDetail.carModel = @"Cruze";
cruzeCarDetail.carMSRP = @"$17,170";
cruzeCarDetail.carMPG = @"46 MPG HWY";
cruzeCarDetail.carAirbag = @"10 Airbags";
cruzeCarDetail.carVolume = @"15.4 Cubic Feet";
cruzeCarDetail.carHorsepower = @"138 HP";
cruzeCarDetail.bigImage = @"big_cruze.jpg";
CarDetail *voltCarDetail = [CarDetail new];
voltCarDetail.carModel = @"Volt";
voltCarDetail.carMSRP = @"$39,145";
voltCarDetail.carMPG = @"101 MPG CTY";
voltCarDetail.carAirbag = @"8 Airbags";
voltCarDetail.carVolume = @"n/a";
voltCarDetail.carHorsepower = @"149 HP";
voltCarDetail.bigImage = @"big_volt.jpg";
CarDetail *malibuCarDetail = [CarDetail new];
malibuCarDetail.carModel = @"Malibu";
malibuCarDetail.carMSRP = @"$21,995";
malibuCarDetail.carMPG = @" 37 MPG HWY";
malibuCarDetail.carAirbag = @"10 Airbags";
malibuCarDetail.carVolume = @"13.2 Cubic Feet";
malibuCarDetail.carHorsepower = @"259 HP";
malibuCarDetail.bigImage = @"big_malibu.jpg";
CarDetail *impalaCarDetail = [CarDetail new];
impalaCarDetail.carModel = @"Impala";
impalaCarDetail.carMSRP = @"$26,725";
impalaCarDetail.carMPG = @"31 MPG HWY";
impalaCarDetail.carAirbag= @"10 Airbags";
impalaCarDetail.carVolume = @"18.8 Cubic Feet";
impalaCarDetail.carHorsepower = @"305 HP";
impalaCarDetail.bigImage = @"big_impala.jpg";
CarDetail *ssCarDetail = [CarDetail new];
ssCarDetail.carModel = @"SS";
ssCarDetail.carMSRP = @"n/a";
ssCarDetail.carMPG = @"n/a";
ssCarDetail.carAirbag = @"n/a";
ssCarDetail.carVolume = @"n/a";
ssCarDetail.carHorsepower = @"415 HP";
ssCarDetail.bigImage = @"big_ss.jpg";
CarDetail *camaroCarDetail = [CarDetail new];
camaroCarDetail.carModel = @"Camaro";
camaroCarDetail.carMSRP = @"$23,345";
camaroCarDetail.carMPG = @"28 MPG HWY";
camaroCarDetail.carAirbag = @"6 Airbags";
camaroCarDetail.carVolume = @"11.3 Cubic Feet";
camaroCarDetail.carHorsepower= @"323 HP";
camaroCarDetail.bigImage = @"big_camaro.jpg";
CarDetail *corvetteCarDetail = [CarDetail new];
corvetteCarDetail.carModel = @"Corvette";
corvetteCarDetail.carMSRP = @"$49,600";
corvetteCarDetail.carMPG = @"26 MPG HWY";
corvetteCarDetail.carAirbag = @"4 Airbags";
corvetteCarDetail.carVolume = @"11.0 Cubic Feet";
corvetteCarDetail.carHorsepower = @"430 HP";
corvetteCarDetail.bigImage = @"big_corvette.jpg";
CarDetail *equinoxCarDetail = [CarDetail new];
equinoxCarDetail.carModel = @"Equinox";
equinoxCarDetail.carMSRP = @"$24,225";
equinoxCarDetail.carMPG = @"32 MPG HWY";
equinoxCarDetail.carAirbag = @"6 Airbags";
equinoxCarDetail.carVolume = @"63.7 Cubic Feet";
equinoxCarDetail.carHorsepower = @"182 HP";
equinoxCarDetail.bigImage = @"big_equinox";
CarDetail *traverseCarDetail = [CarDetail new];
traverseCarDetail.carModel = @"Traverse";
traverseCarDetail.carMSRP = @"$30,795";
traverseCarDetail.carMPG = @"24 MPG HWY";
traverseCarDetail.carAirbag = @"6 Airbags";
traverseCarDetail.carVolume = @"116.3 Cubic Feet";
traverseCarDetail.carHorsepower = @"281 HP";
traverseCarDetail.bigImage = @"big_traverse";
CarDetail *tahoeCarDetail = [CarDetail new];
tahoeCarDetail.carModel = @"Tahoe";
tahoeCarDetail.carMSRP = @"$40,405";
tahoeCarDetail.carMPG = @"21 MPG HWY";
tahoeCarDetail.carAirbag = @"6 Airbags";
tahoeCarDetail.carVolume = @"108.9 Cubic Feet";
tahoeCarDetail.carHorsepower = @"320 HP";
tahoeCarDetail.bigImage = @"big_tahoe";
CarDetail *suburbanCarDetail = [CarDetail new];
suburbanCarDetail.carModel = @"Suburban";
suburbanCarDetail.carMSRP = @"$43,870";
suburbanCarDetail.carMPG = @"21 MPG HWY";
suburbanCarDetail.carAirbag = @"6 Airbags";
suburbanCarDetail.carVolume = @"137.4";
suburbanCarDetail.carHorsepower= @"320 HP";
suburbanCarDetail.bigImage = @"big_suburban";
CarDetail *avalancheCarDetail = [CarDetail new];
avalancheCarDetail.carModel = @"Avalanche";
avalancheCarDetail.carMSRP = @"$35,980";
avalancheCarDetail.carMPG = @"21 MPG HWY";
avalancheCarDetail.carAirbag = @"6 Airbags";
avalancheCarDetail.carVolume = @"n/a";
avalancheCarDetail.carHorsepower = @"320";
avalancheCarDetail.bigImage = @"big_avalanche";
CarDetail *silveradoCarDetail = [CarDetail new];
silveradoCarDetail.carModel = @"Silverado";
silveradoCarDetail.carMSRP = @"$23,590";
silveradoCarDetail.carMPG = @"23 MPG HWY";
silveradoCarDetail.carAirbag = @"6 Airbags";
silveradoCarDetail.carVolume = @"n/a";
silveradoCarDetail.carHorsepower = @"195 HP";
silveradoCarDetail.bigImage = @"big_silverado";
_carDetails = [NSMutableArray new];
[_carDetails addObject:sparkCarDetail];
[_carDetails addObject:sonicCarDetail];
[_carDetails addObject:cruzeCarDetail];
[_carDetails addObject:voltCarDetail];
[_carDetails addObject:malibuCarDetail];
[_carDetails addObject:impalaCarDetail];
[_carDetails addObject:ssCarDetail];
[_carDetails addObject:camaroCarDetail];
[_carDetails addObject:corvetteCarDetail];
[_carDetails addObject:equinoxCarDetail];
[_carDetails addObject:traverseCarDetail];
[_carDetails addObject:tahoeCarDetail];
[_carDetails addObject:suburbanCarDetail];
[_carDetails addObject:avalancheCarDetail];
[_carDetails addObject:silveradoCarDetail];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (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 [_carModels count];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* kCellIdentifier = @"carTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier];
cell.textLabel.text = [_carModels objectAtIndex: indexPath.row];
cell.imageView.image = [UIImage imageNamed:[_carImages objectAtIndex: indexPath.row]];
return cell;
}
#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];
*/
}
-(void) prepareForSegue: (UIStoryboardSegue *)segue sender: (id)sender
{
if ([[segue identifier] isEqualToString:@"ShowCarDetails"])
{
Chevy2DetailViewController *detailViewController = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailViewController.CarDetailModel = @[_carModels[row], _carImages[row]];
}
}
@end
ありがとう!