[__NSCFNumber length]:发送到实例的无法识别的选择器

Józ*_*sza 1 iphone objective-c ios

我试图将数据从表视图控制器传递到详细视图控制器.我的表的每个条目都可以正常工作,除了一个.这是prepareForSegue方法:

- (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"]];

    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的详细视图界面:

#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
Run Code Online (Sandbox Code Playgroud)

这是详细视图的实现文件:

#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
Run Code Online (Sandbox Code Playgroud)

我有问题将idenField的文本设置为iden的文本.我添加了一个异常断点,并确实在此行发生了异常:

[[self idenField] setText:[self iden]];
Run Code Online (Sandbox Code Playgroud)

此时,我已经打印了[self iden]的值,它甚至包含了我想传递的内容,所以我完全不知道问题是什么,因为正如我所说,所有其他字段都正常工作.

抛出的异常是:

2013-08-07 22:28:20.539 NotificationReader[1214:11303] -[__NSCFNumber length]: unrecognized selector sent to instance 0x7587a00
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

Jak*_*cer 7

看起来像:

[destViewController setIden:[notification objectForKey:@"identifier"]];
Run Code Online (Sandbox Code Playgroud)

返回NSNumber而不是NSString.您可以尝试使用以下代码替换该行:

[destViewController setIden:[(NSNumber*)[notification objectForKey:@"identifier"] stringValue]];
Run Code Online (Sandbox Code Playgroud)