IOS/Xcode/Storyboard:如何从 table 行转到模态视图控制器
IOS/Xcode/Storyboard: How can I segue from table row to modal view controller
我认为这是一个故事板问题。
如何创建从 table 行到新视图控制器的转接?
这是它应该是什么样子的图片。
我尝试将控件从 table 拖动到底部的视图控制器,但没有成功。如果我将视图控制器嵌入到导航器中,我可以创建一个 push segue,但是当你点击它时它不起作用。
这是我为此使用的代码,但首先我希望能够复制图片中的故事板。无论如何,我希望在您单击 table 行时弹出新的视图控制器。
- (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 并拖动到下一个视图控制器,给它一个标识符 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];
}
我认为这是一个故事板问题。
如何创建从 table 行到新视图控制器的转接?
这是它应该是什么样子的图片。
我尝试将控件从 table 拖动到底部的视图控制器,但没有成功。如果我将视图控制器嵌入到导航器中,我可以创建一个 push segue,但是当你点击它时它不起作用。
这是我为此使用的代码,但首先我希望能够复制图片中的故事板。无论如何,我希望在您单击 table 行时弹出新的视图控制器。
- (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 并拖动到下一个视图控制器,给它一个标识符 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];
}