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.
Related
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
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.
I am trying to add a Toolbar that is anchored to the bottom of a MonoTouch Dialog.
Here is an example:
So as you scroll, the table's contents scroll but the toolbar at the bottom remains in view always. I know how to do this by using the interface builder, but no clue as to how to do this with Mt.D. Please please tell me it can be done!
To do this, it's probably easiest to use the DialogViewController and its View as a child of another UIViewController.
Just create your public class MyViewController : UIViewController class and then create and size your child views in the override ViewDidLoad method.
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).
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.