如何根据行选择推送视图?

发布于 2024-11-14 17:22:32 字数 889 浏览 1 评论 0原文

在此处输入图像描述/*****更新** ***/第二张图片在此处输入图片描述r.com/YH3cm .png

我是试图弄清楚上图中,我们如何知道用户是否选择了“日期”或“轨迹”。 /已更新/ 我接收的数据是通过选择查询接收的,我创建了一个数组来存储列表。它是动态的,不一定限于两个字段,也可以有 10 个字段。我如何知道选择了哪一行以及如何将数据推送到下一个视图。

就像在 didSelectRowAtIndexPath 中一样,我应该如何在下一个视图上推送日期或跟踪字段?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (dvController == nil) 
  dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];

Teat *obj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];

dvController.obj = obj;
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:dvController animated:YES];

   }

enter image description here/*****UPDATED** ***/Second Imageenter image description herer.com/YH3cm.png

I am trying to figure out in the above image, how will we know if the user has selected Date or Track.
/UPDATED/
The data I am receving is through a select query and I create an array to store the list. It is dynamic and not necessary limited to two fields, it can have 10 fields also. How will I know which row is selected and how will I push the data on to the next view.

Like in didSelectRowAtIndexPath, how should I push the date or track field on the next view?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (dvController == nil) 
  dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];

Teat *obj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];

dvController.obj = obj;
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:dvController animated:YES];

   }

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

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

发布评论

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

评论(3

不寐倦长更 2024-11-21 17:22:32

目前还不是很清楚你想做什么。如果您想根据单元格的内容推送某个视图控制器,但行没有明确的排列,我将使用行索引来访问作为数据源的数组。一些非常松散的代码:

WhateverObject* selectedObject= (WhateverObject*)[tableDataSourceArray objectAtIndex:indexPath.row];
if( [selectedObject hasAnAttributeYouCareAbout] )
{
    MyViewController* theCorrectController= whicheverViewControllerYouWant;
    theCorrectController.anAttribute= aValue;
    [self.navigationController pushViewController:theCorrectController animated:YES];
}

以下是如何使用特定属性定义 UIViewController 子类 MyViewController 的方法。在 .h 文件中:

@interface MyViewController : UIViewController {

     int anAttribute;
}

@property int anAttribute

@end

在 .m 文件中:

@implementation MyViewController

@synthesize anAttribute;

@end

您可以拥有任意数量的任何类型的属性,然后您可以使用 aViewController.anAttribute 设置它们,如上所述。

It's still not very clear what you're trying to do. If you want to push a certain view controller depending on what the content of the cell is, but there is no definite arrangement of the rows, I would use the row index to access the array that is the source of your data. Some very loose code:

WhateverObject* selectedObject= (WhateverObject*)[tableDataSourceArray objectAtIndex:indexPath.row];
if( [selectedObject hasAnAttributeYouCareAbout] )
{
    MyViewController* theCorrectController= whicheverViewControllerYouWant;
    theCorrectController.anAttribute= aValue;
    [self.navigationController pushViewController:theCorrectController animated:YES];
}

And here's how you can define your UIViewController subclass MyViewController with specific attributes. In the .h file:

@interface MyViewController : UIViewController {

     int anAttribute;
}

@property int anAttribute

@end

In the .m file:

@implementation MyViewController

@synthesize anAttribute;

@end

You can have as many attributes as you want of whatever type, and then you can set them with aViewController.anAttribute as above.

幻梦 2024-11-21 17:22:32

创建对象 - dateInfoViewController 和 trackInfoViewController 然后...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

NSInteger row = [indexPath row];
if (row==0)
{
if (self.dateInfoViewController == nil)
     {
    DateInfoViewController *temp = [[DateInfoViewController alloc] init];
    self.dateInfoViewController = temp;
    [temp release];
    }



else {
    dateInfoViewController.title= [ NSString stringWithFormat:@"%@", [sessionInfoDetailsArray objectAtIndex:row]];
    YourAppDelegate *delegate = [[UIApplication sharedApplication]delegate];

    [delegate.sessionNavigationController pushViewController:dateInfoViewController animated:YES]; 
    }
}

  if (row==1)
{
    if (self.vetInfoViewController == nil)
    {
       TrackInfoViewController *temp = [[TrackInfoViewController alloc] init];
        self.trackInfoViewController = temp;
        [temp release];
    }


    else {
        trackInfoViewController.title= [ NSString stringWithFormat:@"%@", [sessionInfoDetailsArray objectAtIndex:row]];
        YourAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
        [delegate.sessionNavigationController pushViewController:trackInfoViewController animated:YES]; 
    }
}

Create objects - dateInfoViewController and trackInfoViewController and then...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

NSInteger row = [indexPath row];
if (row==0)
{
if (self.dateInfoViewController == nil)
     {
    DateInfoViewController *temp = [[DateInfoViewController alloc] init];
    self.dateInfoViewController = temp;
    [temp release];
    }



else {
    dateInfoViewController.title= [ NSString stringWithFormat:@"%@", [sessionInfoDetailsArray objectAtIndex:row]];
    YourAppDelegate *delegate = [[UIApplication sharedApplication]delegate];

    [delegate.sessionNavigationController pushViewController:dateInfoViewController animated:YES]; 
    }
}

  if (row==1)
{
    if (self.vetInfoViewController == nil)
    {
       TrackInfoViewController *temp = [[TrackInfoViewController alloc] init];
        self.trackInfoViewController = temp;
        [temp release];
    }


    else {
        trackInfoViewController.title= [ NSString stringWithFormat:@"%@", [sessionInfoDetailsArray objectAtIndex:row]];
        YourAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
        [delegate.sessionNavigationController pushViewController:trackInfoViewController animated:YES]; 
    }
}
浅浅淡淡 2024-11-21 17:22:32

我担心你想做什么并不完全清楚......如果你需要根据所选行推送不同的视图,你可以简单地执行类似

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.row == 0) 
    //push view 1
else 
    //push view 2

}

UPDATE: Calling indexPath.row 的操作,你会得到所选行的索引。我想您可以根据选择的行来决定要做什么。要将此信息传递到下一个视图,您可能只需考虑要设置的 @property 字段、要调用的方法或要推送的视图控制器的自定义 init 方法。您发布的代码有什么问题?

I fear it's not perfectly clear what do you want to do... if you need to push a different view depending on the selected row you may simply do something like

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.row == 0) 
    //push view 1
else 
    //push view 2

}

UPDATE: calling indexPath.row you get the index of the selected row. I guess is up to you to decide what to do depending on what row is selected. To pass this information to the next view you may simply think of a @property field to set, a method to call or a custom init method for the view controller you are pushing. What is the problem with the code you posted?

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