English 中文(简体)
为每个对象推送新的局部视图
原标题:Pushing new detail view for each object

请帮忙。。。。我有一个带有车辆列表的表格

我想要的是每辆车推送一个视图,其中包含描述每辆车的文本/段落。我是编码新手,所以请尽量保持你的答案简单

这是我的桌子。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;
最佳回答

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

问题回答

暂无回答




相关问题
Plist Hierarchy and All Option

I have a string of data in a plist, which I ve got to display, hierarchically like this: Menu>Chapter>SubChapter>item>item details This might be super simple, in my initial menu, how would I have ...

Disable iPhone table rows

Is there any way to disable the "selectibility" of a UITableView row? Example: I would like to make an appointment for a haircut at a certain time with a certain stylist. What gets displayed to a ...

Nonintrusive visual cue for uitableviewcell

I d like to mark a tableview row in some way that shows it has been clicked by the user. I have a large number of rows and want users to know if they have already visited a particular row. This same ...

TableView oval button for Index/counts

Can someone help me create an index/count button for a UITableView, like this one? iTunes http://img.skitch.com/20091107-nwyci84114dxg76wshqwgtauwn.preview.jpg Is there an Apple example, or other ...

Unable to pushViewController for subview

I have a UINavigationController and I have seperate UIViews that I switch between using a UISegmentControl. On switching the views, I add the view as a subview to my navigation controller s view: [...

热门标签