Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Warning: setTextAlignment deprecated

innertroninnertron Posts: 9New Users
edited July 2009 in iPhone SDK Development
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.

innertrondeprecated.jpg
Post edited by innertron on

Replies

  • deansxdeansx Posts: 127Registered Users
    edited July 2009
    innertron wrote: »
    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:
    [[cell textLabel] setTextAlignment:UITextAlignmentCenter];
    

    Note that, although the UITableViewCell's textLabel property is read-only, properties of the textLabel itself can be set.
    <a href="http://www.blumtnwerx.com" target="_blank"><font face="System"><b><font color="Blue">BluMtnWerx</font></b></font><br />
    </a><br />
    <i>Developers of:</i><blockquote><a href="http://www.blumtnwerx.com/TiltBall.html" target="_blank">TiltBall and T
  • innertroninnertron Posts: 9New Users
    edited July 2009
    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
  • deansxdeansx Posts: 127Registered Users
    edited July 2009
    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)
    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
    <a href="http://www.blumtnwerx.com" target="_blank"><font face="System"><b><font color="Blue">BluMtnWerx</font></b></font><br />
    </a><br />
    <i>Developers of:</i><blockquote><a href="http://www.blumtnwerx.com/TiltBall.html" target="_blank">TiltBall and T
  • innertroninnertron Posts: 9New Users
    edited July 2009
    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
Sign In or Register to comment.