 |
 |
|
 |
07-05-2009, 03:31 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: Colorado
Posts: 9
|
Warning: setTextAlignment deprecated
iPhone SDK 3.0 deprecated issue: Anybody know a why I get a deprecated message for using the following code?
[cell.textLabel setText:@"sometext"];
cell.textAlignment = UITextAlignmentCenter;
I get a deprecated message: warning: 'setTextAlignment deprecated' is deprecated ....
Apparently there is new 3.0 code oput there that APple wants to use. Can;t find it naywhere. Thanks.
innertron
|
|
|
07-05-2009, 09:07 PM
|
#2 (permalink)
|
|
Objective-C Code Monkey
Join Date: May 2009
Location: Mountain View, CA
Posts: 127
|
Quote:
Originally Posted by innertron
iPhone SDK 3.0 deprecated issue: Anybody know a why I get a deprecated message for using the following code?
[cell.textLabel setText:@"sometext"];
cell.textAlignment = UITextAlignmentCenter;
I get a deprecated message: warning: 'setTextAlignment deprecated' is deprecated ....
Apparently there is new 3.0 code oput there that APple wants to use. Can;t find it naywhere. Thanks.
innertron
|
This is consistent with a number of changes made for 3.0.
In 3.0, you don't set the textAlignment property directly on the UITableViewCell. Instead, you set the textAlignment property of the UITableViewCell's textLabel property.
I don't have Xcode handy to compile this, but I think that the code might look something like:
Code:
[[cell textLabel] setTextAlignment:UITextAlignmentCenter];
Note that, although the UITableViewCell's textLabel property is read-only, properties of the textLabel itself can be set.
|
|
|
07-05-2009, 11:31 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: Colorado
Posts: 9
|
deansx
Yes,
you are absolutely right. I used the pertinent portion of teh code as specified here:
[[cell textLabel] setTextAlignment:UITextAlignmentCenter];
[cell.textLabel setText:@"Hello World"];
It worked great. May I ask you. How do you know this ... where did you get this information from. Thank you.
--innertron
|
|
|
07-06-2009, 03:19 PM
|
#4 (permalink)
|
|
Objective-C Code Monkey
Join Date: May 2009
Location: Mountain View, CA
Posts: 127
|
Quote:
|
It worked great. May I ask you. How do you know this ... where did you get this information from. Thank you.
|
I'm glad that it worked. I first encountered the issue when we were testing 3.0. I even included a related fix in a blog post that I wrote about how we were supporting both 2.2 and 3.0 with the same codebase (that's where I copied the code snippet that I sent you from).
The background information is in the Apple UITableViewCell Class Reference documentation. If you mouse over the listing for " textAlignment" in the "Tasks/Managing Text as Cell Content" section (towards the top of the document), you'll get a popup that tells you that the property is deprecated in 3.0, and advising you to adopt the solution described above.
Further down in the document, where the textAlignment property is actually documented, we see: (emphasis mine)
Quote:
textAlignment
A constant that specifies the alignment of text in the cell. (Deprecated. Instead set the text alignment of the UILabel objects assigned to the textLabel and detailTextLabel properties.)
@property(nonatomic) UITextAlignment textAlignment
Discussion
If the value of the property is nil (the default), the title is left-aligned (UITextAlignmentLeft). See the descriptions of the UITextAlignment constants for alternative text alignments.
Availability
Available in iPhone OS 2.0 and later.
Deprecated in iPhone OS 3.0.
Related Sample Code
Reachability
Declared In
UITableViewCell.h
|
|
|
|
07-06-2009, 04:15 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: Colorado
Posts: 9
|
Thank you and good karma
Thank you for going out of your way to show me how you came up with this. You are kind and I wish that tons of good blessed karma descends upon you now!
Seriously though. I am still reading your blog and really like it. I will also go over the items you posted in the thread. I typically have to read things a couple of times before it gets into my noggin.
peace to you.
innertron
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 482 |
| 36 members and 446 guests |
| amulter, applegun, blackspiderman, Blu-print, cdstamper, claijon, cornishGeeza, danny43, dany88, djp_phillips, drhansen, Duncan C, Gi-lo, Grinarn, headkaze, houssem, iGeorG, iphonelover, iruirc, iSdkDev, jbro, JoshuaCaputo, jxdigital, KaBoom, milanjansari, Mopedhead, myPhone, sasose, skunk, sreedharperim, stanny, upperhouse, xslim, Zephyros, _nivek |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,181
Threads: 38,954
Posts: 170,899
Top Poster: smasher (2,565)
|
| Welcome to our newest member, Zephyros |
|