animating from UITableViewCell to a modal view controller - iphone

I have a horizontal UITableView and it has a subclass of a UITableViewCell. I am trying to have an animation where if someone taps on the UITableViewCell the cell does a backflip animation and resizes into a modal view. How and what is the easiest way to do this?

For this you can actually perform exactly what you want using UIView's class method:
transitionFromView:toView:duration:options:completion:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
You could do the following:
Create a clone of the UITableViewCell that has been pressed
Overlay it on the table view at exactly the same position as the pressed cell
Call the method above using the 'from' view as the cloned cell view and the 'to' view as the new 'modal' view (a view that fills the screen).
I recommended that you create a clone otherwise the cell is removed from the tableview:
The starting view for the transition. By default, this view is removed from its superview as part of the transition.
edit: I forgot to mention, the animation that you're looking for is UIViewAnimationOptionTransitionFlipFromBottom

Related

Handling buttons within UITableViewCells

I have a UITableView loading cells from a nib. On each table view cell, there are two buttons. When the button is tapped, I need to update other fields in the view that contains the table view.
In the past I've used a delegate on the table view cell to call back to the view controller to tell it that which button was tapped and used tags on the cell to find the cell's index. The problem I'm currently facing is that this sort of behavior happens in multiple places throughout my application and delegate patterns everywhere could get messy quick.
Is there a better method to message the tableview's parent view controller when a button on a specific cell has been tapped? I need to know which cell was tapped and which button on the cell was tapped.
Yeah, the better method is to make your controller the target of the button's action method. You'll still need to use tags to get the index path of the cell the button was in. You can hook up the action method in IB, or in cellForRowAtIndexPath.

UITableViewController and sub views

I have a screen where I want to display the details of some product. I'm using storyboards.
I have done this using a tableview with static cells, but static cells can only be done within a tableview of UITableViewController. And the problematic point is that I also want to have a Imageview within this controller. this is not possible as the tableview of a UITableViewController take all the screen size.
So I'm doing the Imageview as a subview of the tableview.
I'm wondering if it is the right way to do it, there are similar issues on stackoverflow but none is corresponding to my use case (storyboard + tableviewcontroller + staticcell + sub view)
Without writing any custom code, you could either:
Put a UIImageView in the table view's header or footer view.
Create a static cell and put the UIImageView in that. Table cells don't have to be uniform length, you could make it taller than the other cells if needed.
You can have your subclass of UITableViewController. After you initialize it take its view (tableView) and add it as subview to some other view controller. This way you can set the frame of tableView to occupy the bottom of the (top containing) view controller. To the same view controller you can add additional subviews like UIImageView and position it on the top. The only problems you will encounter might be related to missing notifications to your UITableViewController subclass (viewWillDisappear, viewDidDissappear, viewWillAppear, viewDidAppear, ...). But you can forward them to from your top view controller. Or you could use methods from iOS 5 to add subclass of UITableViewController as a child view controller and position it as you wish. But this is useful if you plan on supporting devices with iOS 5.0+.
See documentation of method in UIViewController:
- (void)addChildViewController:(UIViewController *)childController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
Use a UITableView as a property of the viewController and add it to vc.view, rather than subclass a UITableViewController, then set its frame as you like
Add the imageView to vc. If you need to put it on top of the UITableView, for example, add it as the TableView's header.

pushViewController from Prototype Cell

Quite simply, how do I push a new view controller from a prototype cell within a storyboard? I have a tableView reading data from a plist file, and its one default prototype cell on the storyboard. Then, I have another view controller in the storyboard I need to link to the tapping of a cell on the table view. How can this be accomplished?
Simplest thing would be to Ctrl-click on the prototype cell and drag the line onto the view controller that you want to transition to. It should prompt you for the type of transition—"push" transitions cause the new view controller's view to slide in from the right; "modal" transitions cause the new view to slide in from the bottom. Assuming you're using a navigation controller, the navigation bar should configure the back button automatically. You shouldn't need to write any code to achieve the behavior described in your question.
In your storyboard, link your prototype table view cell to your view
controller with a segue. Make sure to give the segue an identifier in
its Attributes Inspector.
In your TableViewController class,
implement - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
In the prepareForSegue: method, get the NSIndexPath of the row the user tapped with [self.tableView indexPathForSelectedRow]
Use the indexPath to get whatever data you need from your plist. Configure the view controller by using the destinationViewController property of the UIStoryboardSegue parameter passed into prepareForSegue:.

iPhone Dev - Scrolling to a new position in a tableview that is currently off-screen

Say for example I have a tab bar controller where one of its views is a tableviewcontroller, and another one is some other view. The other view has a button in it that when pressed, should make it so the tableview (which is not on the screen while you're pressing the button) repositions itself so that some specified cell is now the top one being displayed when the tableview is again displayed.
My question is this: can I just call [myTableVC.tableView scrollToRowAtIndexPath:someIndex] from inside the other class when the button is pushed? Or does the view actually have to be on the screen when scrollToRowAtIndexPath is called for it to change the top cell that will be displayed?
You may be able to, but you probably shouldn’t—calling view or tableView on an offscreen view controller may cause its view to get loaded into memory unnecessarily. Just set a property—a CGFloat or whatever—on the view controller for the scroll position that it should be at when it appears, and scroll to that position in the controller’s -viewDidLoad or -viewWillAppear:animated:.

iphone dev - activity indicator scroll with the table

In a view of my app I subclass tableViewController and has an activity indicator shown up when the table content is loading. I put it in the center of the screen but it scroll with the tableView (I guess the reason is I add it as a subview of the table view). Is there a way that I can keep the activity indicator in the center of the screen even the table is scrolling?
You could either subclass a UIViewController instead, and set a table property, adding a UITableView as a subclass to the UIView, making it behave exactly like a UITableViewController.
Or, more simply, you could just add the UIActivityIndicator as a subview to the main window.