2013-08-07 3 views
1

테이블 뷰 컨트롤러에서 상세보기 컨트롤러로 데이터를 전달하려고합니다. 내 테이블의 모든 항목은 하나만 제외하고 필요한대로 작동합니다. 여기 [__NSCFNumber 길이] : 인스턴스로 전송 된 인식 할 수없는 선택자

#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 

은 상세 뷰의 구현 파일입니다 : 여기
- (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"]]; 

    } 
} 

가 상세 뷰에 대한 내 인터페이스 : 다음은 prepareForSegue 방법입니다

#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]]; 

: 나는 예외 중단 점을 추가하고, 예외가 참으로이 라인에서 발생하는 것을 가지고있다 그래서 내가 말했듯이, 다른 모든 분야는 그들이해야하는대로 일하고 있기 때문에 문제가 무엇인지 전혀 모른다.

발생되는 예외입니다 :

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

어떤 도움을 크게 감상 할 수있다.

답변

7

는 것 같습니다. 당신이 그 라인을 교체 시도 할 수 :

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

그래, 특히 "식별자"가 처음에 JSON에서 나온 경우 숫자 인 경우 NSNumber가됩니다. * 원본 * JSON (파싱 된 NSObjects의 덤프가 아닌)을 살펴보면 숫자는 따옴표로 묶이지 않지만 문자열 (숫자는 숫자 일 수 있음)은 따옴표로 묶여 있음을 알 수 있습니다. 예 :'{ "식별자": 123} "{"식별자 ":"123 "}'. –

+0

네 말이 맞아! 그것은 완벽하게 작동합니다! 고마워요! –

+0

감사합니다. 잘 작동하고있어. – Raja

3

NSString 대신 NSNumber을 전달하는 지점입니다.

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

가있는 NSString을의 NSNumber 반환되지 않고 : 같은

+0

이 코멘트가 아닌 대답해야 될하기 위해 iden 속성을 변경 :

이보십시오. –

1

텍스트를 설정하려면, idenNSString 할 필요가있다. NSDictionary에서 개체를 가져 오는 경우 NSNumber입니다.

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

을 또는이 NSNumber 다음

[[self idenField] setText:[NSString stringWithFormat:@"%d", [self iden]]];  
관련 문제