Tagged: tips Toggle Comment Threads | Keyboard Shortcuts

  • Koke 1:21 pm on January 25, 2013 Permalink
    Tags: tips   

    Just a tip for working with XIB files: if you need a different XIB file for iPad don’t do this:

    NSString *nibName;
    if (IS_IPAD)
      nibName = @"MyViewController-iPad";
    else
      nibName = @"MyViewController";
    MyViewController *vc = [[MyViewController alloc] initWithNibName:nibName bundle:nil];
    

    Just name the xib files:

    * MyViewController~iphone
    * MyViewController~ipad

    And initialise with

    MyViewController *vc = [[MyViewController alloc] init];
    
     
  • Koke 11:41 am on December 13, 2012 Permalink
    Tags: tips, UITableViewController   

    Table reminder: if a view controller defines it’s own table, it’s probably doing it wrong. If a view controller uses tables, almost every time it should be a subclass of UITableViewController. Doing that, you get a few things for free, in summary:

    • No need to create a .xib or the table view if the view only contains a table
    • Automatically sets delegate and dataSource to self
    • When the table view is about to appear the first time it’s loaded, the table-view controller reloads the table view’s data.
    • Clears table selection every time the table view is displayed.
    • When the table view has appeared, the controller flashes the table view’s scroll indicators.
    • It implements the superclass method setEditing:animated: so that if a user taps an Edit|Done button in the navigation bar, the controller toggles the edit mode of the table.

    There are a few places with potentially unnecessary code:

    ~/automattic/WordPress-iOS (notifications-wptable ✘)✭ ᐅ grep -rl --exclude-dir=Vendor '^@property.*UITableView\b' *                                 
    Classes/AddUsersBlogsViewController.h
    Classes/EditSiteViewController.h
    Classes/JetpackSettingsViewController.h
    Classes/NotificationsCommentDetailViewController.h
    Classes/NotificationsFollowDetailViewController.h
    Classes/NotificationsTableViewDatasource.h
    Classes/PostMediaViewController.h
    Classes/SidebarViewController.h
    Classes/XMLSignupViewController.h
    
     
    • Koke 11:41 am on December 13, 2012 Permalink | Reply

    • Robert 4:53 pm on December 13, 2012 Permalink | Reply

      I don’t think NotificationsTableViewDatasource.h is actually being used so that can be deleted. NotificationsCommentDetailViewController.h doesn’t really use a UITableView in the “standard” way. For one, the UITableView is not the root view of the controller. The only bullet item it would benefit from seems to be:

      Automatically sets delegate and dataSource to self

      But that’s taken care of in the .xib.

      • Koke 5:27 pm on December 13, 2012 Permalink | Reply

        But that’s taken care of in the .xib.

        But you don’t need the .xib 🙂

        • Robert 5:59 pm on December 13, 2012 Permalink | Reply

          Subclassing UITableViewController only works if the view is also the tableView. I just gave it a go and it complains about the root view not being a UITableView and then crashes. The way NotificationsCommentDetailViewController is set up, the view is not a UITableView.

          • Koke 6:01 pm on December 13, 2012 Permalink | Reply

            Yeah, this seems to be one of those few cases 🙂
            I remember having to ditch UITableViewController somewhere else because tableHeaderView wasn’t enough to do the custom UI

            • Robert 6:06 pm on December 13, 2012 Permalink | Reply

              If there where a [UITableView tableHeaderViewDoesNotScroll] property that would allow you to fix the tableHeaderView to the top of the table I think it would take care of most of those customizations.

          • Dan 6:11 pm on December 13, 2012 Permalink | Reply

            I did the same for NotifcationsFollowDetailViewController because it needs a custom header that doesn’t scroll, but also has another header view that should scroll with the content. I couldn’t get it to work properly using a UITableViewController.

            • Robert 6:15 pm on December 13, 2012 Permalink | Reply

              Yeah, that’s the same issue I had, specifically for the note header view.

  • Koke 4:13 pm on February 4, 2011 Permalink
    Tags: tips   

    Cool development tips for iphone: http://iphonedevelopertips.com/
    Some of the articles that might be of interest for us:

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel