Resolved initWithFrame:reuseIdentifier deprecated.

Discussion in 'iOS Programming' started by troop231, Oct 4, 2011.

  1. troop231, Oct 4, 2011
    Last edited: Oct 6, 2011

    troop231 macrumors 603

    Joined:
    Jan 20, 2010
    #1
    I downloaded the GM iOS 5 SDK with Xcode 4.2 and I'm getting this warning. When I run the app on the simulator it works fine, but I'm wondering how would I solve this? Thanks in advance! Screenshot:

    [​IMG]
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    The initWithFrame:reuseIdentifier: method has been deprecated since 3.0 two years ago. Are you just now receiving this warning?
     
  3. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #3
    Yes, which doesn't make sense, as I've been using Xcode 4 for awhile now with the latest 4 SDK.
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    You could have turned off the warnings for deprecated methods a while back and then it somehow got turned back on when you upgraded Xcode. Just a possibility.
     
  5. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #5
    Oh, I see, so how would I fix this warning? My apps have been working fine on iPads running the iOS 5 beta, but the deprecation scares me. Thanks in advance :)
     
  6. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    I would use something like this:
    Code:
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Standard"];
    if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Standard"] autorelease]
    (You can still use cell identifiers and such, I just prefer using strings.)

    I'm still only using Xcode 4.1 and the newest version of iOS 4 (4.3.5? Something like that...) though, so maybe this has been deprecated since and I just haven't heard yet.
     
  7. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #7
    Thanks for the info, do you know if this code is iOS 3 compatible? I'm still maintaining down to iOS 3 to support people who don't upgrade their hardware unfortunately.
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    There was a bug with deprecation warnings not showing for methods that return id, like init methods. I know the method under discussion didn't generate warnings for a long time.

    OP, if you look at the header file that contains the method that has been deprecated you should be able to find out how you fix the problem. Also if you look at the reference docs for the relevant class you should find the method marked as deprecated and instructions on how to fix the issue.
     
  9. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #9
    I looked at the documentation here: http://developer.apple.com/library/...ITableViewCell/initWithStyle:reuseIdentifier:

    Which is what I'm supposed to use now, but I can't figure out how to make it work with my existing code. :confused:
     
  10. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #10
    Did the code I provided a few posts ago not work?

    I checked and the code I gave works on iOS versions as old as iOS 3, which if I'm not mistaken, will run on every iOS device ever made.
     
  11. troop231, Oct 5, 2011
    Last edited: Oct 5, 2011

    troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #11
    I'm still trying to figure out how to implement it with what I currently have, I'm having trouble :(

    Edit: This code seems to work: Does it look right? It works fine on the simulator.

    [​IMG]
     

Share This Page