iOS 5 - 从一个 TableViewController 到另一个 TableViewController
我试图从一个 TableViewController 选择一个详细信息披露按钮(或一行)并继续到另一个 TableViewController,而不将任何数据从第一个 TableViewController 传递到第二个 TableViewController。因此,第一个 TableViewController 几乎充当一个表,它将根据所选的详细信息公开按钮(或行)导航到不同的 TableViewController。
到目前为止,我执行此操作的代码如下所示:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSUInteger rowNumber = [indexPath row];
NSString *categoryCode = [self.categoryCodes objectAtIndex:rowNumber];
self.categoryData = [self.commuterDict objectForKey:categoryCode];
[self performSegueWithIdentifier:@"ShowPlaces" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowPlaces"]) {
PlacesViewController *placesViewController = [segue destinationViewController];
// --> I believe I'm missing something here to access a specific row? <--
}
}
我希望有人可以帮助我!
I'm trying to select a detail disclosure button (or a row) from one TableViewController and segue to another TableViewController, without passing any data from the first to the second TableViewController. So pretty much the first TableViewController acts as a table that will navigate to different TableViewControllers depending on the detail disclosure button (or row) selected.
So far my code for doing this looks like the following:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSUInteger rowNumber = [indexPath row];
NSString *categoryCode = [self.categoryCodes objectAtIndex:rowNumber];
self.categoryData = [self.commuterDict objectForKey:categoryCode];
[self performSegueWithIdentifier:@"ShowPlaces" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowPlaces"]) {
PlacesViewController *placesViewController = [segue destinationViewController];
// --> I believe I'm missing something here to access a specific row? <--
}
}
I hope someone can help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以从 tableView:accessoryButtonTappedForRowWithIndexPath: 函数中的 indexPath 获取特定行。具体来说,被点击的行是indexPath.row。 (如果您的表有多个部分,那么您也可以从indexPath 中读取该部分,但听起来您只是在使用一个简单的表。)
您可以将当前行存储在变量中,然后在prepareForSegue 中读取它:发件人选择去哪里。
You get the specific row from the indexPath in the tableView:accessoryButtonTappedForRowWithIndexPath: function. Specifically, the row that was tapped was indexPath.row. (If your table has multiple sections, then you can read the section out of indexPath, too, but it sounds like you're just using a simple table.)
You can store the current row in a variable and then read it in prepareForSegue:sender to choose where to go.
UIViewController 的
-prepareForSegue:sender:
的文档说:鉴于此,我首先查看
sender
参数,并期望它是指向表格单元格的指针。如果您知道单元格应位于哪个表中,则可以使用-indexPathForCell:
检索单元格的索引路径。The documentation for UIViewController's
-prepareForSegue:sender:
says:Given that, I'd look first at the
sender
parameter and expect it to be a pointer to the table cell. If you know which table the cell should be in, you can use-indexPathForCell:
to retrieve the cell's index path.您可以将 Segue 从视图控制器拖动到按下详细信息披露按钮时想要显示的视图。您可以从代码中触发 segue,如下所示
来自奥地利的干杯
马丁
you can drag segue from the view controller to the view you want to get shown when pressing the detail disclosure button. you can fire the segue from within your code as follows
Cheers from Austria
Martin
如果您的发送者对象是 tableviewcell,则以下代码片段应该有效:
否则请尝试
If your sender object is a tableviewcell, the following code snippet should work:
Otherwise try
您在准备 segue 时使用的发送者可以是您想要的任何发送者。如果您想知道该行,请发送该行或索引路径:
如果您想使用实际行,则将其设为发送者
The sender you use in prepare for segue can be whatever you want. If you want to know the row, send the row, or the index path:
If you want to use the actual row, then make that the sender