---
title: "Unable to set text field on UILabel"  
description: "Unable to set text field on UILabel"  
author: "Anonymous User"  
published: 2015-09-08  
updated: 2015-09-09  
canonical: https://www.mindstick.com/forum/33449/unable-to-set-text-field-on-uilabel  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Unable to set text field on UILabel

I have created UITableCellView [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) called MyCell. The [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags) defines the following:

```
#import< UIKit/UIKit.h>#import "MyNote.h"@interface MyCell : UITableViewCell {    MyNote *note;    UILabel *noteTextLabel;  }@property (nonatomic, retain) UILabel *noteTextLabel;- (MyNote *)note;- (void)setNote:(MyNote *)newNote; @end
```

In the [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) I have the following code for the setNote: [method](https://www.mindstick.com/forum/166/webservice-method):

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

This fails to set the [text field](https://www.mindstick.com/forum/33753/how-to-get-value-from-text-field-on-button-click-in-ios) of the UILabel and the [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) of the log [messages](https://www.mindstick.com/news/4166/google-rolling-out-gemini-extensions-for-messages-whatsapp-and-spotify) is:

2008-11-03 18:09:05.611 VisualNotes[5959:20b] Text [Value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of MyNote = Test Note 1

2008-11-03 18:09:05.619 VisualNotes[5959:20b] Text Value of MyNote Text [Label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better) = (null)

I have also tried to set the text field of UILabel using the following syntax:

[self.noteTextLabel setText:newNote.noteText];

This does not seem to make a difference.

## Replies

### Reply by Anonymous User

Have you set up your noteTextLabel anywhere? What this looks like to me is that you're messaging a nil object. When you cell is created, noteTextLabel is nil. If you never set it up, you're basically doing the following:

```
[nil setText: newNote.noteText];
```

And when you later try to access it, you're doing this:

```
[nil text];
```

Which will return nil.

In your -initWithFrame:reuseIdentifier: method, you need to explicitly create your noteTextLabel, and add it as a subview to your cell's content view:

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

Then this should work.

Also, as a stylistic note, I would make the property for noteTextLabel readonly, since you're only going to want to access it from outside the class, never set it.


---

Original Source: https://www.mindstick.com/forum/33449/unable-to-set-text-field-on-uilabel

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
