Question

I have made an iPhone application, but was trying to tinker with the title in one of my views. When I click on a state on the main page of my application it pushes to a new tableview and the title of the new table view will equal to the state that you chose you on the main page. For example: From the main screen you press the state of California, on the next tableview the title will equal "California", I want it to equal "California Areas".

destViewController.title = destViewController.stateName;

This is the line of code to where it sets the title and also where I feel the word "Areas" should be added. Can anyone assist me with some advice of how to accomplish this?

I feel like it should be something like this:

destViewController.title = destViewController.stateName + @" Areas";

But this doesn't work. I am very new to objective C, so excuse my ignorance.

Thanks

Was it helpful?

Solution

This would work:

destViewController.title = [NSString stringWithFormat:@"%@ Areas", destViewController.stateName];

Update for comment, you could also do:

NSString *newString = [destViewController.stateName stringByAppendingString:@"Areas"];

I prefer the former simply because I think its easier to add and remove stuff to your string. But that being said, if its not going to change much the latter is a bit more succinct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top