ios - TableView View Controller 显示下一个 View

标签 ios core-data tableview

我在 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/

相关文章:

ios - 使用 CoreBluetooth 传输数据

ios - 在 hooks 文件夹中使用节点脚本时出现 cordova 插件安装问题

objective-c - 核心数据 1570 错误代码

php - 当从表中添加/删除列时,如何更新 mysql View ?

ios - 为什么 Date Picker 背景颜色变化在运行时不可见?

ios - 我无法将 TableViewCell 按钮连接到 TableViewController!如何将值从 TableViewCell 连接到 TableViewController?

ios - 同时添加核心数据输入和segue

ios - 核心数据 : Can't modify an immutable model

ios - Tableview 单元格字幕不显示或应用程序退出

java - 在 TableView 中使用 PropertyValueFactory 中的值 - JavaFx