---
title: "Problem in fixing TextField into UILabel"  
description: "Problem in fixing TextField into UILabel"  
author: "Anonymous User"  
published: 2015-10-06  
updated: 2015-10-06  
canonical: https://www.mindstick.com/forum/33494/problem-in-fixing-textfield-into-uilabel  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Problem in fixing TextField into UILabel

I was creating an app using UITableView and the [class name](https://www.mindstick.com/forum/12871/how-to-get-class-name) is CellDemo, so I need to create UITableCellView class, the [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags) [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) is here:

```
#import <UIKit/UIKit.h>#import "Book.h"@interface CellDemo : UITableViewCell {    Book *book;    UILabel *bookTextLabel;  }@property (nonatomic, retain) UILabel *bookTextLabel;- (Book *)book;- (void)setBook:(Book *)newBook; @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 setBook: [method](https://www.mindstick.com/forum/166/webservice-method):

```
- (void)setBook:(Book *)newBook {    book = newBook;    NSLog(@"Text Value of Book = %@", newBook.bookText);    self.bookTextLabel.text = newBook.bookText;    NSLog(@"Text Value of Book Text Label = %@", self.bookTextLabel.text);    [self setNeedsDisplay];}
```

After executing the code it fails and the [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) of log [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) is here:

```
2015-09-09 18:09:05.611 VisualBooks[5959:20b] Text Value of Book = Test Book 1  2015-09-09 18:09:05.619 VisualBooks[5959:20b] Text Value of Book Text Label = (null)
```

And I also try to set the [text field](https://www.mindstick.com/forum/33753/how-to-get-value-from-text-field-on-button-click-in-ios) into UILabel using this code:

```
[self.bookTextLabel setText:newBook.bookText];
```

This also generates same type error.

Please help me.

## Replies

### Reply by Tarun Kumar

Have you set up your bookTextLabel anywhere? What this looks like to me is that you're messaging a nil object. When you cell is created, bookTextLabel is nil. If you never set it up, you're basically doing the following:

```
[nil setText: newBook.bookText];
```

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 bookTextLabel, and add it as a subview to your cell's content view:

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

Then this should work.

Also, as a stylistic book, I would make the property for bookTextLabel readonly, since you're only going to want to access it from outside the [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp), never set it.


---

Original Source: https://www.mindstick.com/forum/33494/problem-in-fixing-textfield-into-uilabel

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
