Unable to set text field to UILabel

I created a class UITableCellViewcalled NoteCell. The header defines the following:

#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

In the implementation, I have the following code for the method 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];
}

This does not allow you to set the text box UILabel, but the output of the log messages:

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)

I also tried setting the text box UILabelusing the following syntax:

[self.noteTextLabel setText:newNote.noteText];

It doesn't seem to matter.

Any help would be greatly appreciated.

+3
source share
1 answer

noteTextLabel? , . , noteTextLabel . , :

[nil setText: newNote.noteText];

, :

[nil text];

.

-initWithFrame:reuseIdentifier: noteTextLabel :

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

.

, property noteTextLabel , , .

+10

Source: https://habr.com/ru/post/1699074/


All Articles