0

iPhoneのデータを正しく表示しているがiPadのデータを表示していないXcodeユニバーサルストーリーボードプロジェクトがあります。以下のコードを使用してデータ配列を初期化しました。

iPhoneでは正常に動作していますが、iPadでデータが表示されず、エラーが発生します。

-[DetailViewController setDataController:]:認識されないセレクターがインスタンスに送信されました

これはAppDelegate.mです

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
     UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
     UINavigationController *navigationController = [splitViewController.viewControllers lastObject];


     MasterViewController *masterViewController = (MasterViewController *)[navigationController topViewController];
      DataController *controller = [[DataController alloc] init];
      masterViewController.dataController = controller;



 splitViewController.delegate = (id)navigationController.topViewController;
 } else {
      // Create the data controller and pass it to the master view controller.
      UINavigationController *navigationController = (UINavigationController  *)self.window.rootViewController;
      MasterViewController *masterViewController = (MasterViewController *)            [navigationController topViewController];
      DataController *controller = [[DataController alloc] init];
      masterViewController.dataController = controller;
 }

コンパイラはDetailViewControllerについて不平を言っています。ここにそのファイルがあります。

 #import "DetailViewController.h"
 #import "Play.h"

@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@end

@implementation DetailViewController
@synthesize masterPopoverController = _masterPopoverController;
@synthesize play;

#pragma mark -
#pragma mark View lifecycle


  - (void)viewWillAppear:(BOOL)animated
 {
  [super viewWillAppear:animated];
// Scroll the table view to the top before it appears
  [self.tableView reloadData];
  [self.tableView setContentOffset:CGPointZero animated:YES];
//self.part = play.part;

  }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UITableViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"Trading Rules That Work", @"Trading Rules That Work");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UITableViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
 {
 // Called when the view is shown again in the split view, invalidating the button and popover controller.
 [self.navigationItem setLeftBarButtonItem:nil animated:YES];
 self.masterPopoverController = nil;
 }


 #pragma mark -
 #pragma mark Table view data source

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// There are 2 sections, for rule, and media, in that order.
return 2;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

//The number of rows varies by section.

NSInteger rows = 0;
switch (section) {
    case 0:
        // For part and date there is just one row.
        rows = 1;
        break;
    case 1:
        // For the media section, there are as many rows as there are media.
        rows = [play.media count];
        break;
    default:
        break;
 }
 return rows;
 }

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

static NSString *CellIdentifier = @"CellIdentifier";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont boldSystemFontOfSize:11];
    cell.textLabel.numberOfLines = 13;

}


NSString *cellText = nil;

switch (indexPath.section) {
    case 0:
        cellText = play.part;
        break;
    case 1:
        cellText = [play.media objectAtIndex:indexPath.row];
        break;
    default:
        break;
}

cell.textLabel.text = cellText;
return cell;
}

 #pragma mark -
 #pragma mark Section header titles

 /*
  HIG note: In this case, since the content of each section is obvious, there's probably       no need to provide a title, but the code is useful for illustration.
  */
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

NSString *title = nil;
switch (section) {
    case 0:
        title = NSLocalizedString(@"Video Description", @"Part section title");
        break;
    case 1:
        title = NSLocalizedString(@"Media", @"Main Media section title");
        break;
    default:
        break;
}
return title;
}

 @end
4

2 に答える 2

1

あなたがするとき

object.property = value;

Objective-C コードでは、これは次のショートカットです。

[object setProperty:value];

dataController プロパティを持っていないように見えるため、setDataController セレクターはありません。

したがって、次のいずれかです。

  • DetailViewController の .h で dataController プロパティを宣言してから、実装で合成するか、または
  • セッターを作成し、インスタンス変数に手動で割り当てます。
于 2012-04-09T22:26:41.447 に答える
0

You are getting this error because in your iPad storyboard you do not have the class set properly for your navigation controller's rootViewController. Make sure the class for that viewController is set to DataController in the Identity Inspector. You probably have this set correctly in your iPhone version storyboard, which is why you don't get the error when running the iPhone version.

于 2012-04-09T22:28:02.737 に答える