subclass uitableview already in a UIView - ios4

I am trying to implement Leah's "Pull to Refresh" code (https://github.com/leah/PullToRefresh) in to my UITableView. However, I have a UIView, so cannot subclass the tableViewController as is required by this.
My structure is
UIView
- UITableView
So there's a UITableView inside my main UIView. I use a UIViewController obviously - and this cannot really change (I think!)
I have tried to change the class in interface builder to the custom uitableviewcontroller above (the pull to refresh one) but it doesn't let me.
Any ideas on how I can subclass the UITableView - NOT the tableViewController??

Here is how I did it:
Change PullToRefreshTableViewController so that it subclasses UIViewController, NOT UITableViewController. Next, add a UITableView * property called tableView to PullToRefreshTableViewController and synthesize it. Lastly, modify your view controller so that it subclasses PullToRefreshTableViewController instead of UIViewController.
That should give you a working implementation of it.

Related

CosmicMind: How to transition between controllers within a container view using Motion

I try to implement the Motion feature with transition from one view controller to another when they are used in a container view.
This is what I want to achive:
Using a UIViewController that includes a container view,
Set the container view with a view controller that includes a table
When user selects the row, I want to transition to another view controller and at the same time animate the image in the table view to the image in the new viewcontroller.
So I have the following UIViewControllers:
Main UIViewController, with a containerView
List UIViewController
Detail UIViewController
No I want to cycle, the list view controller with the detail, with a transition of the image.
Kind of like the PhotoCollectionSample, but within a container view.
I have set the isMotionEnabled = true in the main view controller and the view controllers used in the container. I also have set the same motionIdentifier on the imageViews in both view controllers.
The issue I'm facing is how to transition between the controllers. Since I'm not using the UINavigationController or UITabBarController I don't think the animation is triggered.
At the moment I'm transition between controllers by using the implementation found here.
Switching Child View Controllers in iOS with Auto Layout
But I think I have to do it in another way.
Use this method
/**
A helper transition function.
- Parameter from: A UIViewController.
- Parameter to: A UIViewController.
- Parameter in view: A UIView.
- Parameter completion: An optional completion handler.
*/
func transition(from: UIViewController, to: UIViewController, in view: UIView, completion: ((Bool) -> Void)? = nil)
and call it like this:
Motion.shared.transition(from: vc1, to: vc2, in: container)
That should work :)

How do you add a custom UIViewController to existing XIB?

I am just getting my feet wet with MonoTouch and have the most basic of questions. In their tutorials, they cover adding controls to the XIB directly through XCode's Interface Builder. However, I cannot figure out how to add a custom control to the XIB.
I have seen a number of examples of subclassing the base UICollectionView to customize it for your own purposes, and have done this in C# code in my project. My question is, how do I add that specific subclass of the UICollectionView to the XIB for use in the project?
For a normal UIView, the basic steps you need to go through are:
Create your custom view in C# as a class
public class MyView
{
}
Add the UIView base class to it, add a Register attribute and add two constructors:
[Register("MyView")]
public class MyView : UIView
{
public MyView() {}
public MyView(IntPtr handle) : base(handle) {}
}
To make it do something useful, then add a Draw implementation:
public override Draw(RectangleF rect)
{
var context = UIGraphics.CurrentGraphics();
UIColor.Red.SetFill();
context.FillEclipseInRect(rect);
}
Save and Build your project
Now in the XIB editor for the UIViewController in which you want to use your custom view, add a UIView to the design surface
Select that UIView and in the Identity Inspector, set the UIView's "Custom Class" to "MyView"
Save everything in xCode
Return to MonoDevelop, build and run
There's a video of this flow available at:
- http://www.youtube.com/watch?v=ggwO46dd-50&feature=youtube_gdata
For a custom UICollectionView, UILabel, UITableViewCell, or any other UIView base class, then you follow similar steps, just with a different base class and with different constructors too in order to support the specific View.
For a video about custom Table cells, see: http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html

iOS how to display new UIView?

New to iOS dev. Kindly correct me if i am wrong?
I have a UIWindow, and rootviewcontroller is :
#interface ViewController : UIViewController
{
IBOutlet UIButton *but;
}
#property (nonatomic, strong) UIButton *but;
-(IBAction) butButtonPressed;
#end
ie: If i make this Viewcontroller as a root view controller, the UIView that is available in the ViewController is displayed. Understood.
I have created a new class inherited from UIViewController, and along with its .xib file.
So xib file name is : view1.xib,
My Objective is to display this view when the button is pressed.
Now i have created a button and button press invokes butButtonPressed. Inside of butButtonPressed, i did the following.
myViewController *vcontroler = [[ViewController alloc] initWithNibName:#"view1" bundle:nil];
[self.view.window addSubview:vcontroler.view];
Application crashes. What am i doing wrong ? Kindly point out.
This...
[self.view.window addSubview:vcontroler.view];
...is a really bad strategy (and I seriously wish I knew where people are finding it as a way of showing views). If you create a view controller, you should use it rather than just treating it as a temporary container that you can rip views out of.
If you want vcontroler to look like a child of your first controller (and you have a UINavigationController), use pushViewController:animated:. Otherwise you can show it as modal with presentModalViewController:animated:.
If you only want to add a view to the existing display, put the view in ViewController's hierarchy and show/hide it.
If you absolutely must have it as a sub-controller of ViewController then you need to keep a reference to it and manage its lifecycle inside the owning controller.

How to load view if UIViewController is having more than one UIView

In my app i have one UIViewController and there are many UIView which i want to load on particular action (for instance BTN Tap) so how can i achieve this programatically .
if any one has solution please let me know.
Thnx in advance
you can bind all the views using IBOutlet like suppose you have view1 and view2 and one default view. Now you want to display view1 on btnTap then you can do like this [self.view addSubview:view1]; make sure to bind the view using IBOutlet
You can use the addSubview method of UIView, like this:
[controller.view addSubview:subview];
where controller is your UIViewController (of course, if you are putting that code inside of it, your controller is self).

Is there anyway nested xib with another xib file?

What I want to do, I have a UIView with UIToolbar via IB, and the UIToolbar is customized via IB, what I want to set is set the UIToolbar by xib file, not load from source?
is it possible?
Thanks.
Create UIToolbar in UIView XIB-file.
Change class of UIToolbar from UIToolbar to MyCustomToolbarSubclass(choose yours subclass) in IB.
It's important to have this MyCustomToolbarSubclass for your custom UIToolbar. And you have to declare parent as UIToolbar. Change Object, UIViewController or anything you choose as parent class when create new class for your UIToolbar.
Also there are too many solves any problems with custom toolbars. It helps me.

Resources