繁体   English   中英

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

[英][__NSCFNumber length]: unrecognized selector sent to instance

我试图将数据从表视图控制器传递到详细信息视图控制器。 我的表中的每个条目都可以正常工作,除了一个。 这是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"]];

    }
}

这是我的详细视图界面:

#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

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

#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

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

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

在这一点上,我已经打印了[self iden]的值,甚至包含了我想要传递的内容,所以我完全不知道问题出在哪里,因为正如我所说,所有其他字段都在正常工作。

抛出的异常是:

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

任何帮助将不胜感激。

看起来像:

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

返回一个NSNumber而不是一个NSString。 您可以尝试将该行替换为:

[destViewController setIden:[(NSNumber*)[notification objectForKey:@"identifier"] stringValue]];

在某个地方传递NSNumber而不是NSString

要设置文本, iden必须是NSString NSDictionary获取对象时,它是一个NSNumber

尝试这个:

[destViewController setIden:(NSString *)[notification objectForKey:@"identifier"]];

或将iden属性更改为NSNumber ,然后

[[self idenField] setText:[NSString stringWithFormat:@"%d", [self iden]]];    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM