Advertise here




Advertise here

Howdy, Stranger!

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

Sign In with Google Sign In with OpenID

Badges

Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Duncan C

About

Username
Duncan C
Joined
Visits
2,513
Last Active
Roles
Tutorial Authors, Registered Users
Points
375
Badges
18
Posts
8,036
Location
Northern Virginia
  • Using static table views in iOS 6 using "embed" segues

    I've been studying Storyboards and the things they let you do. Specifically, I wanted to learn how to set up static table views. Static table views don't require a data source. However, a static table view must be managed by a UITableViewController.

    The downside of that is that a UITableViewController is set up so it's content view is its table view. You really can't make a UITableViewController manage a complex set of views where a table view is only a part.

    I therefore set myself the challenge of making a view controller that managed 2 different static table views, and got notified when the user selected a cell in either table view.

    With iOS 6 this is easy. There is a new user interface object called a container view. You drag a container view onto a view controller and it becomes a container that hosts the contents of another view controller. You then right-click-and-drag from the container view to another view controller and tell IB (Interface Builder) you want to create an embed segue, and it does all the housekeeping for you. (Thanks to GHuebner for showing me how to do this.)

    So, if you're willing to use iOS 6 or later, it's actually pretty easy to include one or more static table views in your UI design.

    The screen from the app looks like this:

    image

    There is a working project on github (link) that you can clone, or just download for read-only access.

    Here is a description of what the project and a very rough outline of how you do it:

    Static table view demo project.
    Requires iOS 6.0

    This project demonstrates several things. It is based on Storyboards, which requires iOS 5.0. It also uses the new embed segue which was added in iOS 6.

    1. Using the automatic view controller containment supported with storyboards under iOS 6.0.

    Steps to enclose a view controller in another view controller:

    a) Display the objects library in the utilities area,
    b) Type "container" into the filter bar.
    c) Copy a container view onto your view controller.
    d) Create a second view controller scene in your storyboard (a table view controller, for this project.)
    e) Right-drag/control drag from your container view to your new view controller, and select "embed". This creates an embed segue, which tells the system to set up the "contained" view controller as a child of the containing view controller.

    2. Using static table views (Must be managed by a UITableViewController.)

    a) Define a custom subclass of UITableViewController in your project. (Let's call it MyTableViewController.)
    b) Create a UITableViewController in your storyboard.
    c) Go to the identity inspector and switch the class of your table view controller to your custom class.
    d) Select the table view inside the new table view controller and select the attributes inspector.
    e) Switch the content type to "Static cells"
    f) Set up the cells in your table view as desired. (Use custom cell type)
    g) If needed, control-drag from the fields of your cells into the header of your table view controller to create outlets and/or actions.

    3. Creating links between your parent and child view controller

    Saving a link to the child view controller:

    a) Click on the embed segue and give it a unique identifier
    b) Implement a prepareForSegue method in your parent view controller.
    c) In that prepareForSegue method, string match the segue identifier (using the NSString isEqualToString method) and for the desired embed segue, save the destination view controller

    4. Setting up the parent view controller as a delegate of the child view controller:

    a) Define a protocol for the parent view controller.
    b) Add a delegate property in the child view controller that conforms to the parent view controller protocol.
    c) Add code to the prepareForSegue method that sets the delegate property of the destination view controller


    5. Making taps in table view cells select/deselect the cell:

    a) Implement table view tableView:willSelectRowAtIndexPath: and tableView:didSelectRowAtIndexPath: methods.
    b) Add logic to toggle selected state of cell if it was selected previously.

    6. Passing cell selected actions to parent view controller through delegate property:

    a) Add a method to the StaticTableParentProtocol to notify the delegate when the user selects/deselects a cell.
    b) Update MyTableViewController's tableView:didSelectRowAtIndexPath method to see if delegate responds to new method, and send message if it does.

    7. Construct and display localized message in parent view controller as the user selects/deselects cells in each table view

    a) Implement new StaticTableParentProtocol method in parent view controller to display message when user selects/deselects a cell.
    b) Use NSLocalizedString for all string constants to localize strings for display.

    8. Add buttons to static table view cells

    a) Make sure cells are custom type
    b) drag a round rect button onto a cell
    c) Add a text label (since the custom cell does not have a text label by default.)
    d) Make the button shorter to fit inside the table view cell.
    e) Duplicate the custom cell with button as many times as needed
    f) Put sequential numbered tags on the buttons for each cell, 1..n
    g) Create a "cellButtonTapped" IBAction method in the custom table view
    h) Link each button's touch up inside action to the cellButtonTapped method.


    9. Update MyTableViewController to send a message to parent view controller when user presses buttons on cells, and use add code in MyTableViewController to display a localized message telling the user which button was clicked, and in which table view.

    a) Design a new method tableView:clickedButton:withTag:inViewController: in StaticTableParentProtocol to notify parent when user taps a button.
    b) Update MyTableViewController's cellButtonTapped method to check delegate to see if it responds to tableView:clickedButton:withTag:inViewController: method, and send the message if it does
    c) Implement tableView:clickedButton:withTag:inViewController: method in parent view controller. Make the method construct a localized message about which button tag was clicked, and in which view controller.

    10. Add a rounded-corner, colored border around the table views:

    a) Add CALayer category with a method setBorderUIColor that takes a UIColor as input and sets the layer's border color with that UIColor's CGColor.
    b) Add "User Defined Runtime Attributes" to container views with key/value pairs
    "self.layer.borderWidth"/1 (NSNumber)
    self.layer.borderUIColor/blue (color)
    self.layer.cornerRadius/10 (NSNumber)
    self.layer.masksToBorder/YES (BOOL)


    The "User Defined Runtime Attributes" look like this:

    image
    ryantcb
  • Can I upload the same app twice with different names?

    My company is essentially 2 companies and we have separate clientele. Management wants me to make it so if the user searches the respective company name the results will show an app with that name. These two apps would be identical except for their names and an image or two. Is this possible at all?
    You would need to change the app name and the bundle ID. If the 2 companies are really the same company then you could upload it from the same developer account.

    The unknown question is if the app review group would reject the second app as being too similar to the first. I would certainly suggest submitting them separately, and on different days, just to make that less likely.
    anon_1776
  • initWithNibName to Storyboard

    kosicki123;415290 said:
    Guys,

    How to convert this code to be used on storyboard?
    I did this past week but I forgot how to make this...

    [HTML]- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (self.details == nil) {
    self.details = [[PalestranteDetailViewController alloc]initWithNibName:@"PalestranteDetailViewController" bundle:nil];
    }
    FailedBankInfo *info = [_palestranteInfos objectAtIndex:indexPath.row];
    _details.id_pal = info.id_pal;
    [self.navigationController pushViewController:_details animated:YES];
    }[/HTML]

    Just remember that this is returning me a black screen because I don't have the .xib file. I wish to learn how to convert to storyboard...
    Thanks in advance
    You can mix and match storyboards and nib files in the same project if you want to. Your app can have more than one storyboard, and 0 or more nib files.

    That said, if you want to convert to a storyboard-based app, you need to redesign your app.

    Instead of having separate nib files for each view controller, you set up the definitions of all your view controllers in the storyboard file. I believe you can copy and paste views from nib files into a storyboard view controller "scene", although I haven't tried it. The only work I've done with storyboards so far has been to create new projects, not convert existing nib-based projects.

    When you set up a view controller "scene" using a Storyboard, you assign a string identifier to each view controller that you want to be able to invoke manually. You then use the storyboard method instantiateViewControllerWithIdentifier to create an instance of a view controller.

    instantiateViewControllerWithIdentifier is the storyboard equivalent of initWithNibName.
    undeadlegion
  • UINavigationController Transition Animation.

    nick.keroulis;403237 said:
    I have 2 UIViewControllers:

    First & Second.

    - I try to make the transition from First to Second but it displays an error
    saying that both UIViewControllers must have the same parent.

    OK,

    - I made a new UIViewController named Container and i added 2 childs to that
    Container. The First and the Second. Before anything displays on the screen
    it displays an error saying that the First (which is the rootViewController)
    must not have a parent.

    - DAFUQ?

    Ok, here's what to do:

    Let's say you have parentVC, childVC1, and childVC2.

    in the viewDidLoad for parentVC,

    [self addChildViewController: childVC1];
    [self addChildViewController: childVC2];


    Then, add the content view for the one you want to appear first:

    [self.view addSubview childVC1.view];



    Then, when you want to swtich, use the transitionFromViewController: method.

    Baja's proposed Google search yields a link with info on another way to do it, using a normal navigation controller and simply changing the transition type.

    objective c - UINavigationController custom transition animation on Back button - Stack Overflow

    SecondView *newView = [[SecondView alloc] initWithNibName:nil bundle:nil];
    [UIView beginAnimtaions:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown];
    [self.navigationcontroller pushViewController:newView animated:NO];
    [UIView commitAntimations];
    [newView release];
    sudonathan
  • Code suddenly stopped working on device still fine on simulatorr

    The fact is that the requestAccessToAccountsWithType:options:completion method you are using is only supported under 6.0. As to why you did not crash yesterday, the answer is unclear. It should have crashed.

    I have run across quite a few cases where things work on the simulator that do not work on the device. The simulator actually runs under Mac OS, not iOS, with a fairly loose-and-sloppy mapping of calls to make it look like you are running under iOS. If you search the Mac OS docs for requestAccessToAccountsWithType:options:completion:, you will find that that method is listed. Thus, when you run on the simulator, the call is mapping to the Mac OS version, even though it shouldn't.

    Try setting your base SDK to 5.1 and recompiling for the device. If you do that, you will get warnings for any API calls you are trying to do that are not supported under 5.1. That's a useful exercise to see what calls your code is making that won't work in the lower OS versions. You can then switch the base SDK back to 6.0, set the deployment target to your lowest supported iOS version, and take your iOS 6 only code and add runtime checks for those OS features, and either implement alternative code or turn that feature off for older OS versions.
    ryantcb