Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[__NSCFNumber length]: unrecognized selector sent to instance

I am trying to pass data from a table view controller to a detail view controller. Every entry of my table works just as it should, except for one. Here is the prepareForSegue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"showDetails"]) {
        NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
        NSDictionary *notification = [[self notifications] objectAtIndex:[indexPath row]];
        NRDetailViewController *destViewController = [segue destinationViewController];
        [destViewController setDate:[notification objectForKey:@"date"]];
        [destViewController setFrom:[notification objectForKey:@"from"]];
        [destViewController setIden:[notification objectForKey:@"identifier"]];
        [destViewController setPriority:[notification objectForKey:@"priority"]];
        [destViewController setSubject:[notification objectForKey:@"subject"]];
        [destViewController setMessage:[notification objectForKey:@"text"]];

    }
}

Here is my interface for the detail view:

#import <UIKit/UIKit.h>

@interface NRDetailViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *dateField;
@property (weak, nonatomic) IBOutlet UITextField *fromField;
@property (weak, nonatomic) IBOutlet UITextField *idenField;

@property (weak, nonatomic) IBOutlet UITextField *prioField;
@property (weak, nonatomic) IBOutlet UITextField *subjectField;
@property (weak, nonatomic) IBOutlet UITextView *messageView;


@property (copy, nonatomic) NSString *date;
@property (copy, nonatomic) NSString *from;
@property (copy, nonatomic) NSString *iden;
@property (copy, nonatomic) NSString *priority;
@property (copy, nonatomic) NSString *subject;
@property (copy, nonatomic) NSString *message;


@end

Here is the detail view's implementation file:

#import "NRDetailViewController.h"

@interface NRDetailViewController ()

@end

@implementation NRDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[self dateField] setText:[self date]];
    [[self fromField] setText:[self from]];
    [[self idenField] setText:[self iden]];
    [[self prioField] setText:[self priority]];
    [[self subjectField] setText:[self subject]];
    [[self messageView] setText:[self message]];



}

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

@end

I have problem setting the text of idenField to the text of iden. I have added an exception breakpoint, and got that the exception indeed occurs at this line:

[[self idenField] setText:[self iden]];

At this point, I have printed the value of [self iden] and it even contains the content I want to pass, so I have absolutely no idea what the problem is, since as I said, all the other fields are working as they should.

The exception being thrown is:

2013-08-07 22:28:20.539 NotificationReader[1214:11303] -[__NSCFNumber length]: unrecognized selector sent to instance 0x7587a00

Any help would be appreciated greatly.

like image 497
József Vesza Avatar asked Dec 05 '25 03:12

József Vesza


1 Answers

It looks like:

[destViewController setIden:[notification objectForKey:@"identifier"]];

is returning an NSNumber and not an NSString. You could try replacing that line with:

[destViewController setIden:[(NSNumber*)[notification objectForKey:@"identifier"] stringValue]];
like image 112
Jake Spencer Avatar answered Dec 06 '25 16:12

Jake Spencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!