Monday, April 2, 2012

XCode StoryBoarding and SplitViews

So I burnt a lot of time last week trying to get XCode Storyboards working nicely with UISPlitViews on the iPad.  One of the more helpful resources was this one:

which I found by searching Google for "programmatically trigger segue".  My previous search for "splitviewcontroller segue" was less helpful, turning up short, not really relevant StackOverflow posts.

I also skimmed the following tutorial, but wasn't able to pull the information I wanted fast enough:

Ultimately I got it all working, and I think the biggest roadblock was the idea that the segues still needed to be created in the StoryBoard interface, but that I would trigger them and catch them programmatically.  Given that I wanted different segues to take place depending on whether the user clicked a table cell in the master view, or the associated detail disclosure button.  The trick was to have segues in the Storyboard running from the master view to two other UI views, one for each of the possible segues, but then adjusting the segue type to specify the detail view to ensure that the right part of the splitviewcontroller was updated.

Particularly after some not too disimilar trials and tribulations with Android fragments it makes me wonder if there isn't some way to make mobile development a little less hazardous ...

Of course having got that working there was still the unpleasantly convoluted issue of trying to make the test in a UITableViewCell wordwrap to keep me entertained:

I kind of hacked a solution there.  It seems remarkable that there isn't a dynamic sizing solution that doesn't require hacking at code - maybe I just haven't found it yet.

I think I was also also tripped up by the detailTextLabel not being visible:

All my attempts to set a nice background gradient for some elements in the table view failed :-( The top three StackOverflow hits for my google search on "CAGradientLayer UILabel" seemed promising, but I couldn't get it to work.  I did however manage to get something to appear by creating a dummy transparent PNG of the right size and then was able to dynamically create a UILabel with a number on it.

No comments: