在 Storyboard 中推送视图
我正在尝试使用表视图和导航控制器。如果我使用 NIB 文件,这是我将使用的代码。如果我使用 NIB 文件,这段代码可以正常工作,但我决定尝试故事板 -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
}
我在故事板中创建了另一个场景,并在那里设置了所有内容。当用户单击此表视图中的单元格时,他们将被带到该场景。这是我为代码编写的内容,但它不正确,我陷入了绝望的困境:( -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"articleView"]){
UINavigationController *navigationController = segue.destinationViewController;
WebViewController *controller = (WebViewController *)navigationController.topViewController;
controller.webView = self;
}
答案 - 答案 2 和 3 都是正确的
I am trying to use Table Views and navigation controllers. This is the code I would use if I was using NIB files. This piece of code would work fine if I was using NIB files, but I decided to try storyboard -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
}
I have created another scene in storyboard and have everything set up out there. When a user clicks a cell in this Table View they will be taken to that scene. This is what I wrote for the code but it is not right and I'm hopelessly stuck :( -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"articleView"]){
UINavigationController *navigationController = segue.destinationViewController;
WebViewController *controller = (WebViewController *)navigationController.topViewController;
controller.webView = self;
}
Answer - Answers 2 and 3 are both right
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
两天前我遇到了一个非常类似的问题,用户连续选择披露附件并想要调用 segue。对我有用的:
为了你,我还用 tableView:didSelectRowAtIndexPath: 进行了测试,它有效。
享受吧,
达米安
I had a very similar problem 2 days ago, with the user selecting the disclosure accessory on a row and wanting to invoke a segue. What worked for me:
Just for you I also tested with tableView:didSelectRowAtIndexPath: and it works.
Enjoy,
Damien
如果您的表格视图已经嵌入到导航控制器中(从您的第一个代码片段来看就是这样),那么您的 segue 的目标视图控制器将是 WebViewController,而不是导航控制器。
因此,您可以让prepareForSegue方法直接传递项目:
If your table view is already embedded in a navigation controller (looks that way, from your first code snippet) then the destination view controller of your segue will be a WebViewController, not a navigation controller.
You can therefore have your prepareForSegue method pass the item directly across :
您可能会发现这个优秀的两部分教程很有帮助
http:// /www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
You may find this excellent two-part tutorial helpful
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1