为每个对象推送新的详细信息视图

时间:2012-01-16 06:08:30

标签: ios5 uitableview xcode4.2 master-detail

请帮助....我有一张带有车辆清单的桌面视图

我想要的是每个车辆用文字/段落来描述这些车辆。我是编码的新手,所以请尽量保持简单的答案

这是我的table.h

#import <UIKit/UIKit.h>

@interface table_1 : UITableViewController
{
    NSMutableArray *vehicle;
}

@end

这是我的table.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

这是detailview.h

#import <UIKit/UIKit.h>

@interface detailview : UIViewController
    {

        IBOutlet UILabel *lblText;
        NSString *selectedVehicle;
    }
@property (nonatomic, retain) NSString *selectedVehicle;

@end

这是detail.m

#import "detailview.h"

@implementation detailview
@synthesize selectedVehicle;

1 个答案:

答案 0 :(得分:0)

Xcode 4.2有一个Master-Detail Application项目模板,它为您尝试实现的master-detail应用程序提供了一个起点。