1

C/xcode オタク!

私はこのエラーに何時間も悩まされてきましたが、解決策が見つからないようですが、多くの人がまったく同じ問題を抱えているようです.

コードを参照してください:

//
//  ListViewController.m
//  Puns
//
//  Created by Amit Bijlani on 12/13/11.
//  Copyright (c) 2011 Treehouse Island Inc. All rights reserved.
//

#import "ListViewController.h"
#import "BlogPost.h"
//#import "Pun.h"
#import "PunsTableViewCell.h"
#import "DetailViewController.h"

@implementation ListViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark - Segue

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"0");
    if ( [[segue identifier] isEqualToString:@"ShowMenu"] ){
        NSLog(@"1");
        DetailViewController *dvc = (DetailViewController *)[segue destinationViewController];
        dvc.menu = [self.blogPosts objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
    }
}

#pragma mark - View lifecycle


- (void)viewDidLoad
{
    [super viewDidLoad];

    // GET WEB DATA SOURCE (JSON)

    // The url
    NSURL *blogURL = [NSURL URLWithString:@"http://constantsolutions.dk/json.html"];

    // The data
    NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];

    // Error variable
    NSError *error = nil;

    // jsonData to serialization
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

    // Get array 'posts'
    self.blogPosts = [NSMutableArray array];
    NSArray *blogPostsArray = [dataDictionary objectForKey:@"posts"];

    for (NSDictionary *bpDictionary in blogPostsArray) {
        // Get title
        // Will only retrieve data, if TITLE exists

        BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]];

        // Get the content
        blogPost.content = [bpDictionary objectForKey:@"content"];

        // Get thumbnail
        blogPost.thumbnail = [bpDictionary objectForKey:@"thumbnail"];

        // Get date
        blogPost.date = [bpDictionary objectForKey:@"date"];

        // Get price
        blogPost.price = [bpDictionary objectForKey:@"price"];

        // Add the object to blogPosts array
        [self.blogPosts addObject:blogPost];
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.blogPosts count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PunTableViewCell";

    PunsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PunsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    BlogPost *blogPost = [self.blogPosts objectAtIndex:indexPath.row];

    cell.menuTitle.text = blogPost.title;
    cell.menuContent.text = blogPost.content;

    if([blogPost.price length] == 0) {
        [cell.menuPrice setHidden:YES];
    } else {
        cell.menuPrice.text = blogPost.price;
    }



    return cell;
}


@end

ご覧のとおり、prepareForSegue 内に NSLog() を実装しましたが、トリガーされません。

私が間違っていることを知っていますか?私はこれにかなり慣れていないので、まだこの iPhone 開発全体を把握していません。解決策が簡単な場合は、私と一緒にやり直してください:o)。

前もって感謝します!

4

1 に答える 1

1

セグエの名前があるので、ボタンまたはテーブル ビュー セルから他のビュー コントローラーにドラッグして作成し、それを選択して xcode で名前を付けたということですか? ビューをプログラムで変更している場合は呼び出されませんが、ビューを交換する前に手動でメソッドを呼び出して準備することができます

答えが役立つ可能性があるビュー間でiosで情報を共有する際に、同様の問題がありました。

特に、彼が言うその投稿の答えから:

「あなたの.mファイルでは、セグエをトリガーします-おそらくボタンまたは何らかのアクションで。すでにこれを持っているように聞こえます:」

[self performSegueWithIdentifier:@"viewB" sender:self];

--

もちろん、セグエ名を交換します。

于 2013-05-27T18:40:50.567 に答える