コントローラーを表示する必要があります (UpcomingReleaseViewController および ReleaseController)。
JSON を使用してアプリにデータを入力しています。
私のアプリのメイン ページは UpcomingReleasesViewController です。セルをクリックすると、リリース ページに移動して詳細情報が表示されるはずですが、何らかの理由でセルをクリックするたびに空白のページに移動します。
ReleaseView.h
@interface ReleaseViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *releaseView;
@property (strong, nonatomic) NSString *release_name;
@end
ReleaseView.m
@interface ReleaseViewController ()
@end
@implementation ReleaseViewController
@synthesize releaseView = _releaseView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.releaseView.text = self.release_name;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
UpcomingReleaseViewController.m
#import "UpcomingReleasesViewController.h"
#import "UpcomingRelease.h"
#import "ReleaseViewController.h"
@interface UpcomingReleasesViewController ()
@end
@implementation UpcomingReleasesViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *upcomingReleasesURL = [NSURL URLWithString:@"http://obscure-lake-7450.herokuapp.com/upcoming.json"];
NSData *jsonData = [NSData dataWithContentsOfURL:upcomingReleasesURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.upcomingReleases = [NSMutableArray array];
NSArray *upcomingReleasesArray = [dataDictionary objectForKey:@"upcoming_releases"];
for (NSDictionary *upcomingReleaseDictionary in upcomingReleasesArray) {
UpcomingRelease *upcomingRelease = [UpcomingRelease upcomingReleaseWithReleaseName:[upcomingReleaseDictionary objectForKey:@"release_name"]];
upcomingRelease.release_price = [upcomingReleaseDictionary objectForKey:@"release_price"];
upcomingRelease.release_date = [upcomingReleaseDictionary objectForKey:@"release_date"];
upcomingRelease.thumbnail = [upcomingReleaseDictionary objectForKey:@"thumbnail"];
upcomingRelease.url = [NSURL URLWithString:[upcomingReleaseDictionary objectForKey:@"url"]];
[self.upcomingReleases addObject:upcomingRelease];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UpcomingRelease *upcomingRelease = [self.upcomingReleases objectAtIndex:indexPath.row];
NSData *imageData = [NSData dataWithContentsOfURL:upcomingRelease.thumbnailURL];
UIImage *image = [UIImage imageWithData:imageData];
cell.imageView.image = image;
cell.textLabel.text = upcomingRelease.release_name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ — $%@",[upcomingRelease formattedDate], upcomingRelease.release_price];
return cell;
}
#pragma mark - View Upcoming Release
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue.identifier isEqualToString:@"showRelease"] ) {
ReleaseViewController *rvc = (ReleaseViewController *)[segue destinationViewController];
rvc.release_name = [self.upcomingReleasesArray objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
}
}
@end
ストーリーボード セグエの名前は正しく (showRelease)、UITextView を ReleaseViewController (releaseView) にリンクしました。たぶん、今後のReleasesArrayと関係がありますか?私はiOSが初めてで、何が問題なのかわかりません。