xcode - iOS/Xcode/ Storyboard : How can I segue from table row to modal view controller

标签 xcode storyboard segue

我认为这是一个 Storyboard问题。

如何创建从表行到新 View Controller 的 Segue?

这是一张它应该是什么样子的图片。

storyboard screenshot

我尝试将控件从表格拖动到底部的 View Controller ,但没有成功。如果我将 View Controller 嵌入到导航器中,我可以创建一个推送转场,但当您单击它时它不起作用。

这是我正在使用的代码,但首先我希望能够复制图片中的 Storyboard。无论如何,我希望当您单击表格行时弹出新的 View Controller 。

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Store Selection
    [self setSelection:indexPath];
}


...

else if ([segue.identifier isEqualToString:@"updateToDoViewController"]) {
            NSLog(@"segue to update");

            // Obtain Reference to View Controller
            UpdateTodoVC *vc = (UpdateTodoVC *)[segue destinationViewController];

            // Configure View Controller
            [vc setManagedObjectContext:self.managedObjectContext];

            if (self.selection) {
                // Fetch Record
                NSManagedObject *record = [self.fetchedResultsController objectAtIndexPath:self.selection];

                if (record) {
                    [vc setRecord:record];
                }

                // Reset Selection
                [self setSelection:nil];
            }
        }
    }

感谢您的任何建议。

最佳答案

您无法从“原型(prototype)”单元格中按住 Ctrl 键并拖动!您只能使用静态单元格来做到这一点。因此,您必须从 UITableViewController 按住 Ctrl 键并拖动到下一个 View Controller ,为其指定 updateToDoViewController 标识符,并以编程方式执行 segue:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Store Selection
    [self setSelection:indexPath];

    // Perform the segue with identifier: updateToDoViewController
    [self performSegueWithIdentifier:@"updateToDoViewController" sender:self];
}

关于xcode - iOS/Xcode/ Storyboard : How can I segue from table row to modal view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28143914/

相关文章:

ios - 从 parse.com 检索指针中包含的对象 ID

ios - 如何使用 Storyboard UI 在 Main WIndow 之外添加 UIViews?

ios - ViewController 通过在屏幕上交换转到上一个 ViewController

cocoa - 如何使用 Storyboard将 NSTextField 中的文本绑定(bind)到 Controller 上的属性值?

ios - 无法从维基百科 API 恢复图像并将其显示在另一个 View Controller 中

ios - 程序化转场后自动触发的 Action

iphone - 控制台错误 : UICollectionView must be initialized with a non-nil layout parameter

objective-c - 向基于窗口的 iPhone 应用程序添加交互式标签

linux - 使用 xCode 的 Linux 初学者编程?

wpf - 使用 wpf VisualStateManager 动画可见性和不透明度