2012-01-02 22 views
0

スプリットビューコントローラアプリケーションを作成しようとしていて、レシピチュートリアルに従っていました。しかし、このチュートリアルはXcode 4.2より前のものであり、正しく動作しません。私はXcode 4.2とストーリーボードのための簡単なチュートリアルを見てきましたが、何も見つかりませんでした。とにかく私のコードと私のエラーは、下のいずれかのヘルプは非常に高く評価されます!SplitViewController NSNotificationsを使用してXcode 4.2で他のビューを開く

エラー:

2012-01-02 16:37:40.061 blackdahlia[2233:f803] -[DetailViewController recieveNotification]: unrecognized selector sent to instance 0x6c35650 
2012-01-02 16:37:40.063 blackdahlia[2233:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController recieveNotification]: unrecognized selector sent to instance 0x6c35650' 
*** First throw call stack: 
(0x13be052 0x154fd0a 0x13bfced 0x1324f00 0x1324ce2 0x9c9a39 0x1389885 0x13897a8 0x90e1aa 0x91ab13 0x334b 0xa571d 0xa5952 0x92d86d 0x1392966 0x1392407 0x12f57c0 0x12f4db4 0x12f4ccb 0x12a7879 0x12a793e 0x15a9b 0x2688 0x25e5 0x1) 
terminate called throwing an exception 

MasterViewController.m

#import "MasterViewController.h" 

#import "DetailViewController.h" 

@implementation MasterViewController 

@synthesize detailViewController = _detailViewController; 
@synthesize anotherdetailViewController; 
@synthesize recipeArray, recipe; 


- (void)awakeFromNib 
{ 
    self.clearsSelectionOnViewWillAppear = NO; 
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); 
    [super awakeFromNib]; 

    recipeArray = [[NSMutableArray alloc] init]; 

    recipe = [[Recipe alloc] init]; 

    recipe.name = @"Sex on the Beach"; 
    recipe.instructions = @"Sexy Instructions"; 
    recipe.image = [UIImage imageNamed:@"testimage.jpg"]; 
    [recipeArray addObject:recipe]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

} 

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

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [recipeArray count]; 
} 

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

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

    recipe = [recipeArray objectAtIndex:indexPath.row]; 

    cell.textLabel.text = recipe.name; 

    return cell; 
} 

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    anotherdetailViewController.recipe = [recipeArray objectAtIndex:indexPath.row]; 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Test" object:self]; 
    NSLog(@"NOTIFICATION SENT"); 
} 

/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 
*/ 

/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source. 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
} 
*/ 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 
*/ 

@end 

DetailViewController.m

#import "DetailViewController.h" 

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

@implementation DetailViewController 

@synthesize detailItem = _detailItem; 
@synthesize detailDescriptionLabel = _detailDescriptionLabel; 
@synthesize masterPopoverController = _masterPopoverController; 
@synthesize recipe, imageView; 

#pragma mark - Managing the detail item 

- (void)setDetailItem:(id)newDetailItem 
{ 
    if (_detailItem != newDetailItem) { 
     _detailItem = newDetailItem; 

     // Update the view. 
     [self configureView]; 
    } 

    if (self.masterPopoverController != nil) { 
     [self.masterPopoverController dismissPopoverAnimated:YES]; 
    }   
} 

- (void)configureView 
{ 
    // Update the user interface for the detail item. 

    if (self.detailItem) { 
     self.detailDescriptionLabel.text = [self.detailItem description]; 
    } 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveNotification) name:@"Test" object:nil]; 
} 

- (void)recieveNotification:(NSNotification *) notification{ 

    if ([[notification name] isEqualToString:@"Test"]) { 
     self.navigationItem.title = recipe.name; 
     [self.imageView setImage:recipe.image]; 
     NSLog(@"Notification Recieved"); 
    } 
} 

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

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

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

#pragma mark - Split view 

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

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)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; 
} 

@end 

答えて

0

あなた-receiveNotification:メソッドは、引数としてNSNotificationがかかりますが、あなたはするセレクタを指定しています通知はになる。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveNotification) name:@"Test" object:nil]; 

結腸がないことに注意してください。これは、通知が実際に- (void)receiveNotification:(NSNotification *)notificationの代わりに- (void)receiveNotificationというシグネチャを持つメソッドを探していることを意味します。

関連する問題