ios - UITableView prepareForSegue 没有推送到 UIWebView

标签 ios objective-c xcode uitableview uiwebview

我正在尝试从 WebListViewController 推送至 WebPageViewController ,所以当一个单元格被按下时,它会被推送到 UIWebView显示与之关联的网络文章。但我就是无法让它工作-

WebListViewController.m

#import "WebListViewController.h"
#import "Feed.h"

@interface WebListViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end

@implementation WebListViewController
@synthesize tableView = _tableView;
@synthesize headlinesArray;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"standardCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
    NSString *headlineText = [NSString stringWithFormat:@"%@", feedLocal.headline];
    cell.textLabel.text = headlineText;

    return cell;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"webpage"]) {
    UITableViewCell *cell = (UITableViewCell*)sender;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

    WebPageViewController *wpvc = (WebPageViewController *) [segue destinationViewController];
    wpvc.buttonNumber = _buttonNumber;
    Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
    NSString *stringWeb = [NSString stringWithFormat:@"%@", feedLocal.links.web.href];
    wpvc.stringWeb = stringWeb;
}

WebPageViewController.h

@interface WebPageViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic) int buttonNumber;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) NSString *stringWeb;
@end

WebPageViewController.m

#import "WebPageViewController.h"
#import "Feed.h"

@interface WebPageViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end
@implementation WebPageViewController
@synthesize stringWeb;
@synthesize headlinesArray;

-(void)viewWillAppear:(BOOL)animated {
    NSURL *url = [NSURL URLWithString:stringWeb];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

-(void)viewWillDisappear:(BOOL)animated {
    [self.webView stopLoading];
}

JSON 响应

{
    "timestamp": "2013-05-04T16:38:48Z",
    "feed": [{
        "headline": "Text of headline",
        "links": {
            "web": {
                "href": "http://website.com/article"
            },

我刚刚添加了 <UIWebViewDelegate>今天的一部分,因为我想也许这就是正在发生的事情,但它仍然没有用。我知道cellForRowAtIndexPath是正确的,因为我在控制台中看到了所有正确的数据。当我运行程序时,它似乎永远不会到达 WebPageViewController。 , 所选单元格保持突出显示。我不知道问题出在哪里,如果它是 prepareForSegue或者需要添加 didSelectRowAtIndexPath或不同的东西。

(我正在从 API 中提取 JSON 数据。)

任何建议都会非常有用,我会添加任何需要的代码,谢谢!

最佳答案

我猜 standardCell 是您在 Storyboard中定义为原型(prototype)单元的单元?如果是这样,请确保您右键单击该单元格并将“选择”属性拖动到您希望单元格推送到导航 Controller 的 View Controller 。

How to create a segue connection to another view controller

此外,确保第一个 View 嵌入在导航 Controller 中。如果不是,请在 Storyboard中选择它,然后转到编辑器菜单,选择“嵌入”,然后选择“导航 Controller ”。

How to embed a view in a navigation controller

关于ios - UITableView prepareForSegue 没有推送到 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379453/

相关文章:

objective-c - 如何从应用程序委托(delegate)加载登录 View Controller

xcode - 我想使 tableView 方法静态化

ios - Xcode - 更改框架的搜索路径

iphone - 弱链接 iPhone 应用程序的多个框架 (-weak_framework)

ios - 为 NSArray 中的对象运行 NSTimer

ios - 获取 IAP 原始购买日期?

javascript - React Native Swift 模块中的回调函数

objective-c - 以 Retina 质量屏蔽 2 个 UIImages

objective-c - iOS:发送短信

ios - iOS:自定义对象上的FilterUsingPredicate