为每个对象推送新的细节视图

发布于 2024-12-27 05:15:26 字数 3909 浏览 1 评论 0原文

请帮忙....我有一个包含车辆列表的表格视图

,我想要的是每辆车都推送一个带有描述每辆车的文本/段落的视图。我是编码新手,所以请尽量让您的答案简单,

这是我的表。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

这是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;

please help .... i have a tableview with a list of vehicle

what i want is each of those vehicles to push a view with a text/paragraph describing each of those vehicles. I am new to coding so please try to keep your answers simple

this is my table.h

#import <UIKit/UIKit.h>

@interface table_1 : UITableViewController
{
    NSMutableArray *vehicle;
}

@end

this is my 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

this is detailview.h

#import <UIKit/UIKit.h>

@interface detailview : UIViewController
    {

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

@end

this is detail.m

#import "detailview.h"

@implementation detailview
@synthesize selectedVehicle;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2025-01-03 05:15:26

Xcode 4.2 有一个主从应用程序项目模板,它为您尝试实现的主从应用程序提供了一个起点。

Xcode 4.2 has a Master-Detail Application project template which provides a starting point for the master-detail application you're trying to implement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文