请帮忙。。。。我有一个带有车辆列表的表格
我想要的是每辆车推送一个视图,其中包含描述每辆车的文本/段落。我是编码新手,所以请尽量保持你的答案简单
这是我的桌子。h
#import <UIKit/UIKit.h>
@interface table_1 : UITableViewController
{
NSMutableArray *vehicle;
}
@end
这是我的桌子。m
#import "table 1.h"
#import "detailview.h"
@implementation table_1
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren t in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
vehicle = [[NSMutableArray alloc] init];
[vehicle addObject:@"sedan"];
[vehicle addObject:@"van"];
[vehicle addObject:@"suv"];
[vehicle addObject:@"truck"];
// 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)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (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 for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#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 [vehicle count];
}
- (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];
}
// Configure the cell...
cell.textLabel.text = [vehicle objectAtIndex:indexPath.row];
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//return UITableViewCellAccessoryDetailDisclosureButton;
return UITableViewCellAccessoryDisclosureIndicator;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedcar = [vehicle objectAtIndex:indexPath.row];
detailview *dvController = [[detailview alloc] initWithNibName:@"detailview" bundle:[NSBundle mainBundle]];
dvController.selectedVehicle = selectedcar;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
}
@end
这是详细视图。h
#import <UIKit/UIKit.h>
@interface detailview : UIViewController
{
IBOutlet UILabel *lblText;
NSString *selectedVehicle;
}
@property (nonatomic, retain) NSString *selectedVehicle;
@end
这是细节。m
#import "detailview.h"
@implementation detailview
@synthesize selectedVehicle;