Вопрос

The problem lies on my didSelectRowAtIndexPath , once I click the cell the this appears on my Debug Area, I don't understand it, I'm sorry people because i'm only a beginner for now.

2014-05-08 12:59:41.118 MyWishlistV2[1334:60b] -[NSManagedObject wishlistItem]: unrecognized selector sent to instance 0x8e69c80 2014-05-08 12:59:41.121 MyWishlistV2[1334:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject wishlistItem]: unrecognized selector sent to instance 0x8e69c80'

What I am trying to accomplish is that when I click the cell, it will go to the other ViewController(DetailViewController) but I don't know why this ain't working. Can someone check what I am doing wrong here? Here is my code.

#import "WishTableViewController.h"
#import "WishlistItem.h"
#import "DetailViewController.h"

@interface WishTableViewController ()

@property (strong) NSMutableArray *wishes;

@end

@implementation WishTableViewController

- (NSManagedObjectContext *)managedObjectContext
{
    NSManagedObjectContext *context = nil;
    id delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }
    return context;
}

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

- (void)viewDidLoad
{
    [super viewDidLoad];

}

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

    // Fetch the wishes from persistent data store
    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Wish"];
    self.wishes = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.wishes.count;
}


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

    // Configure the cell...
    NSManagedObject *wish = [self.wishes objectAtIndex:indexPath.row];

    //Set Wish
    NSString *myWish = [wish valueForKey:@"wishItem"];
    NSString *myTargetDate = [wish valueForKey:@"wishTargetDate"];

    cell.textLabel.text = myWish;
    cell.detailTextLabel.text = myTargetDate;

    return cell;
}



// 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
{
    NSManagedObjectContext *context = [self managedObjectContext];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [context deleteObject:[self.wishes objectAtIndex:indexPath.row]];

        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
            return;
        }
    }

    // Remove wish from table view
    [self.wishes removeObjectAtIndex:indexPath.row];
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    WishlistItem *wish = [self.wishes objectAtIndex:indexPath.row];
    DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"dvcID"];

    dvc.wishItemStr = wish.wishlistItem;
    dvc.dateItemStr = wish.targetDate;
    dvc.descItemStr = wish.descWishItem;


    [self.navigationController pushViewController:dvc animated:YES];


}

@end
Это было полезно?

Решение

Its important to setup and use NSFetchedResultsController for example

MyObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top