我在 Storyboard中使用 TableView Controller 。
我目前在 Storyboard的导航 Controller 中嵌入了一个 tableview Controller 。此 TableView Controller 链接到 ObjectiveC 文件。
通过代码,我可以使用 tableView didSelectRowAtIndexPath 方法显示另一个具有正确数据的 TableView Controller 。
代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
[self.navigationController pushViewController:detailViewController animated:YES];
}
但是如果我尝试在 Storyboard 中添加另一个 TableView Controller ,将其与 ObjectiveC View Controller 文件关联并将第一个 TVC 连接到它,运行代码时不会显示该 TableView Controller 。
我需要在视觉上自定义第二个 TableView 并尝试使用 segue 推送...如下所示:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"show"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
//WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
WorkoutSetViewController *destViewController = segue.destinationViewController;
destViewController.workoutType = workoutType;
//[self.navigationController pushViewController:detailViewController animated:YES];
}
}
但是当我运行这段代码时,尽管应用程序没有崩溃,但第二个 TableView Controller 甚至没有加载。
无论我做错了什么,都必须很简单,我们将不胜感激。
谢谢
最佳答案
简单你必须浏览下面的代码。 (在同一个 Storyboard ViewController 中工作时无需设置 Storyboard)
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexpath.row==0)//for first row click
{
WorkoutSetViewController *objWorkoutSetVC=[[WorkoutSetViewController alloc] i nitWithNibName:@"WorkoutSetViewController" bundle:nil];
[self.navigationController pushViewController:objWorkoutSetVC animated:YES];
}
else if(indexpath.row==1)//for second row click
{
//Put code in which screen you have to navigate
}
}
关于ios - TableView View Controller 显示下一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18295119/