32

I'm trying to capitalize all letters in a NSString for a table cell label.

Here's my code:

  // cell title and subtitle
cell.nameLabel.text = listingNode.title;
[cell.nameLabel.text uppercaseString];

It doesn't seem to have any effect at all.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
user2588945
  • 1,681
  • 6
  • 25
  • 38
  • 1
    Try cell.nameLabel.text = [listingNode.title uppercaseString]; – AnkitJain Sep 02 '13 at 10:45
  • @AnkitJain normally before posting a comment/solution, one would look at the several answers that were already posted to see if that same solution had been provided. In this case, 5 identical answers were posted several minutes earlier. – mah Sep 02 '13 at 10:53
  • @mah I didn't realize that it had been answered already. My mistake. – AnkitJain Sep 02 '13 at 11:04
  • @AnkitJain it's ok, answer overlaps happen frequently, just not usually with so much time between them on simple answers ;) – mah Sep 02 '13 at 11:07

5 Answers5

80

The method uppercaseString returns an uppercased representation of the receiver. Which means you need to collect the returned string and apply that to the label as text.

Try this,

NSString *uppercase = [cell.nameLabel.text uppercaseString];
cell.nameLabel.text =  uppercase;
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Amar
  • 13,202
  • 7
  • 53
  • 71
4
NSString * str=@"jit";

NSLog(@"%@",[str uppercaseString]);


cell.nameLabel.text=[str uppercaseString];
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jitendra
  • 5,055
  • 2
  • 22
  • 42
2

You need to just convert your string to uppercase

cell.nameLabel.text=[String_name uppercaseString];
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Agent Chocks.
  • 1,312
  • 8
  • 19
1

What do you think about that.

cell.nameLabel.text = [listingNode.title uppercaseString];
Emon
  • 452
  • 3
  • 11
  • 21
0

uppercaseString returns a value - NSString that contains the result of the operation.

cell.nameLabel.text = [listingNode.title uppercaseString];
likeToCode
  • 371
  • 3
  • 3