문제

내가 만들었다 UITableCellView 클래스 호출 NoteCell. 헤더는 다음을 정의합니다.

#import <UIKit/UIKit.h>
#import "Note.h"

@interface NoteCell : UITableViewCell {
    Note *note;
    UILabel *noteTextLabel;  
}

@property (nonatomic, retain) UILabel *noteTextLabel;

- (Note *)note;
- (void)setNote:(Note *)newNote; 

@end

구현에는 다음과 같은 코드가 있습니다. setNote: 방법:

- (void)setNote:(Note *)newNote {
    note = newNote;
    NSLog(@"Text Value of Note = %@", newNote.noteText);
    self.noteTextLabel.text = newNote.noteText;
    NSLog(@"Text Value of Note Text Label = %@", self.noteTextLabel.text);
    [self setNeedsDisplay];
}

이것은 텍스트 필드를 설정하지 않습니다 UILabel 로그 메시지의 출력은 다음과 같습니다.

2008-11-03 18:09:05.611 VisualNotes[5959:20b] Text Value of Note = Test Note 1  
2008-11-03 18:09:05.619 VisualNotes[5959:20b] Text Value of Note Text Label = (null)

나는 또한 텍스트 필드를 설정하려고 노력했다. UILabel 다음 구문 사용 :

[self.noteTextLabel setText:newNote.noteText];

이것은 차이가없는 것 같습니다.

어떤 도움이든 큰 감사를드립니다.

도움이 되었습니까?

해결책

어디서나 nonetextlabel을 설정 했습니까? 이것이 나에게 보이는 것은 당신이 nil 객체를 메시지에 보내는 것입니다. 셀이 만들어지면 NOTETEXTLABEL은 NIL입니다. 설정하지 않으면 기본적으로 다음을 수행하고 있습니다.

[nil setText: newNote.noteText];

그리고 나중에 액세스하려고 할 때 다음을 수행하고 있습니다.

[nil text];

Nil을 반환합니다.

당신의 -initWithFrame:reuseIdentifier: 방법, notetextlabel을 명시 적으로 만들고 셀의 내용보기에 하위 뷰로 추가해야합니다.

self.noteTextLabel = [[[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 20)] autorelease];
[self.contentView addSubview: self.noteTextLabel];

그러면 이것은 작동해야합니다.

또한 스타일의 메모로서 나는 property notetextlabel readonly의 경우, 클래스 외부에서 액세스하기를 원하기 때문에 절대 설정하지 않기 때문입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top