如何根据行选择推送视图?
/*****更新** ***/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];
}
/*****UPDATED** ***/r.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前还不是很清楚你想做什么。如果您想根据单元格的内容推送某个视图控制器,但行没有明确的排列,我将使用行索引来访问作为数据源的数组。一些非常松散的代码:
以下是如何使用特定属性定义
UIViewController
子类MyViewController
的方法。在 .h 文件中:在 .m 文件中:
您可以拥有任意数量的任何类型的属性,然后您可以使用
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:
And here's how you can define your
UIViewController
subclassMyViewController
with specific attributes. In the .h file:In the .m file:
You can have as many attributes as you want of whatever type, and then you can set them with
aViewController.anAttribute
as above.创建对象 - dateInfoViewController 和 trackInfoViewController 然后...
Create objects - dateInfoViewController and trackInfoViewController and then...
我担心你想做什么并不完全清楚......如果你需要根据所选行推送不同的视图,你可以简单地执行类似
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
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?