菜鸟教程小白 发表于 2022-12-12 10:48:26

ios - UITableView prepareForSegue 不推送到 UIWebView


                                            <p><p>我正在尝试从 <code>WebListViewController</code> 推送到 <code>WebPageViewController</code>,因此当按下单元格时,它将推送到 <code>UIWebView</code> 以显示与之相关的网络文章。但我就是不能让它工作-</p>

<p><strong>WebListViewController.m</strong></p>

<pre><code>#import &#34;WebListViewController.h&#34;
#import &#34;Feed.h&#34;

@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 = @&#34;standardCell&#34;;
    UITableViewCell *cell = ;

    Feed *feedLocal = ;
    NSString *headlineText = ;
    cell.textLabel.text = headlineText;

    return cell;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if () {
    UITableViewCell *cell = (UITableViewCell*)sender;
    NSIndexPath *indexPath = ;

    WebPageViewController *wpvc = (WebPageViewController *) ;
    wpvc.buttonNumber = _buttonNumber;
    Feed *feedLocal = ;
    NSString *stringWeb = ;
    wpvc.stringWeb = stringWeb;
}
</code></pre>

<p>}</p>

<p><strong>WebPageViewController.h</strong></p>

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

<p><strong>WebPageViewController.m</strong></p>

<pre><code>#import &#34;WebPageViewController.h&#34;
#import &#34;Feed.h&#34;

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

-(void)viewWillAppear:(BOOL)animated {
    NSURL *url = ;
    ];
}

-(void)viewWillDisappear:(BOOL)animated {
    ;
}
</code></pre>

<p><strong>JSON 响应</strong></p>

<pre><code>{
    &#34;timestamp&#34;: &#34;2013-05-04T16:38:48Z&#34;,
    &#34;feed&#34;: [{
      &#34;headline&#34;: &#34;Text of headline&#34;,
      &#34;links&#34;: {
            &#34;web&#34;: {
                &#34;href&#34;: &#34;http://website.com/article&#34;
            },
</code></pre>

<p>我今天刚刚添加了 <code><UIWebViewDelegate></code> 部分,因为我认为这可能是正在发生的事情,但它仍然无法正常工作。我知道 <code>cellForRowAtIndexPath</code> 是正确的,因为我在控制台中看到了它的所有正确数据。当我运行程序时,它似乎从未到达 <code>WebPageViewController</code>,所选单元格保持突出显示。我无法弄清楚问题是什么,如果它的 <code>prepareForSegue</code> 或需要添加 <code>didSelectRowAtIndexPath</code> 或其他不同的东西。</p>

<p>(我从 API 中提取 JSON 数据。)</p>

<p>任何建议都会非常有帮助,我会添加任何需要的代码,谢谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我猜 standardCell 是您在 Storyboard 中定义为原型(prototype)单元的单元?如果是这样,请确保您右键单击该单元格并将“选择”属性拖动到您希望单元格推送到导航 Controller 上的 ViewController 。</p>

<p> <img src="/image/Avs3P.png" alt="How to create a segue connection to another view controller"/> </p>

<p>另外,确保第一个 View 嵌入在导航 Controller 中。如果不是,请在 Storyboard 中选择它,然后转到 Editor-menu,选择“Embed In”,然后选择“Navigation Controller”。</p>

<p> <img src="/image/0egAd.png" alt="How to embed a view in a navigation controller"/> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UITableView prepareForSegue 不推送到 UIWebView,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/16379453/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/16379453/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UITableView prepareForSegue 不推送到 UIWebView