I'm having issues assigning a custom class in storyboard.
In past projects I have overridden/subclassed UIPageControl to a custom class (ZZPageControl) by adding the .h to the view with the UIPageControl.
#import "MyPageControl.h"
#interface ScrollerVC : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;
IBOutlet MyPageControl *pageControl;
NSMutableArray *viewControllers;
BOOL pageControlUsed;
}
Then in IB I assign my custom class instead of UIPageControl.
Except my new project uses Storyboard rather than separate XIBs. When selecting the UIPageControl in the view and checking its class in the Identity Inspector only UIPageControl is listed. If I type MyPageControl is doesn't stick.
I've tried adding #import "MyPageControl.h" in the app delegate, in the view that initiates the UINavigation control, in the .pch file. I can't get my custom class to show up in the Storyboard.
How can I override the UIPageControl in the StoryBoard view?
Related
See this storyboard containing a Navigation View, Gestures, and a few Views.
Also within is a TabView, which contains an UIImageView and UITableViewController.
To apply my data to this TableView, I need to assign a Controller by using msExampleTableViewController.
The problem: the input/dropdown field removes entry after pressing Enter (like if this class is not assignable).
What is wrong here, and how can it best be done?
NA UITableViewController does assume that the root view will be a UITableView. When you combines UITableView with others controllers.. you can do in your Controller (ViewController in your case):
#interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, assign) IBOutlet UITableView* tableView;
In Interface Builder set both the delegate and dataSource outlets of the table view to be equal to its superview's view controller (File's Owner)...
Now, Your view controller implementation should be the typical TableViewController implementation: cellForRowAtIndexPath, etc.
In my application, I have a button that pushes a custom view controller (MenuViewController) on click.
#interface MenuViewController : UITableViewController
I wasn't able to resize the tableview. I tried:
self.tableView.frame=CGRectMake(0, 0,100, 100);
self.View.frame=CGRectMake(0, 0,100, 100);
in viewDidLoad and viewWillAppear. Neither of these methods worked.
I have an idea of creating a UIView initwithframe:.. and add MenuViewController as a subview.
Is this the proper way to do it?
MenuViewController is basically a general control that will handle variable init inputs
and will display the cells according to the inputs, the problem is the frame of the table view.
I believe that if you inherit from UIViewController and expose the UITableView as a property and also on the Interface then you can resize it. When you are using UITableViewController then it will always display in full size mode.
UPDATE:
So instead of doing something like this:
#interface TasksViewController : UITableViewController
{
}
You can do something like this:
#interface TasksViewController : UIViewController<UITableViewDelegate>
{
}
#property (nonatomic,weak) IBOutlet UITableView *tableView;
Also make sure that in interface builder you have a UITableView which is hooked to the tableView property in the TasksViewController. Now in your implementation file implement the cellForRowAtIndexPath method and return the cell.
I have few common views in most of my viewControllers. What I noticed is that I can reuse single code for all viewControllers which is absolutely wise. For this I decided to create a class Utils which has static methods like
+(void)createCommonViews:(float)yAxis:(NSString*)text;
In my case common views are three labels and two images.
Problem : I am not able to add these views from Utils. I am wondering how can I send self as a parameter so that I may add the views from Utils. It may be wrong to add views outside the viewController. In that case what can be the solution? Taking all these views in a UIView, setting return type of Utils method as UIView and then adding UIView to viewController (after calling method from viewController) might solve my problem. But what I am looking for is some other solution.
+(void) createCommonViews:(float)yAxis withText:(NSString*) text toTarget:(UIViewController*) target
{
//create views
[target addSuview:view];
}
But I think returning a Uiview and then adding it in the UIViewController afterwards, is a far better solution.
The method you're attempting is to have your view object as a singleton. This is uncommon at best, at worst a crash waiting to happen. Better design is for each of your view controller classes to have its own instance of your custom view, like so:
#interface MyCommonView : UIView
// ...
#end
#interface MyViewController_A : UIViewController {
MyCommonView *commonView;
}
#property (strong, nonatomic) IBOutlet MyCommonView *commonView;
#end
// Meanwhile somewhere else...
#interface MyViewController_B : UIViewController {
MyCommonView *commonView;
}
#property (strong, nonatomic) IBOutlet MyCommonView *commonView;
#end
Create a viewController that acts as a parent view for all your common stuff, call it CommonViewController then implement this in all the viewcontrollers you want it to appear
-(void) viewDidLoad
{
[self.view addSubView:[[CommonViewController alloc] initWithRect:..];
}
Or alternatively using xib files
I was wondering how to connect my custom class and my .xib. In Interface Builder I have changed the class of the Files Owner to my custom class. I then created an IBOutlet and connected it to the view of the .xib. I then added an instance of my custom class to my UIViewController. My custom class is a subclass of UIView, so I set the background of it to black and can see it appear on top of my UIViewController. What I can't see is my .xib???? Here is my code for my custom class... (FreeThrow is my custom class... FetView is my .xib)
#interface FreeThrow : UIView {
IBOutlet UIView *mySquareView;
}
#property(nonatomic, retain)IBOutlet UIView *mySquareView;
-(void)createMe;
#end
#implementation FreeThrow
#synthesize mySquareView;
-(void)createMe {
[self addSubview:mySquareView];
[self setBackgroundColor:[UIColor blackColor]]; // I did this to know my UIViewController is showing this class... which it is
}
#end
Here is my code for what I call from my UIViewController...
freeThrowView = [[FreeThrow alloc] init];
[freeThrowView createMe];
freeThrowView.frame = CGRectMake(8, 42, 335, 230);
[self addSubview:freeThrowView];
What code do I need to add? What do I need to do? What is the problem? Why is my .xib not showing up.
Sadly apple doesn't give us a way to truly link a xib to a view via IB alone. You'll have to do it via instantiation. Here are some past answers to similar questions:
How do I associate a nib (.xib) file with a UIView?
Loading .xibs into a UIView
I am trying to use UITabController as may controller in my main window and add navigation controllers to some tab bar items.
For example, the first tab has a navigation controller with table view:
alt text http://www.freeimagehosting.net/uploads/f3ad987c86.png
The SettingsViewController is associated with its own NIB file, where a table view is defined. Within that xib file, I have a table view and set it to the outlet of SettingsViewController class property myTableView.
Here are my h files:
// header file for SettingViewController class
#interface SettingsViewController :
UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *myTableView;
// other codes vars
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
// ...
#end
// header for main app delegate
#interface MainAppDelegate :
NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
// ...
}
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
// ...
#end
In my SettingsViewController.xib file, through IB, I linked outlet myTableView to the xib's file owner, ie, SettingViewController class:
alt text http://www.freeimagehosting.net/uploads/e577d35137.png
The problem is that in the main xib file, for the SettingsViewController navigation, there is one outlet myTableView. I am not sure if I have to set this to somewhere?
The exception I get is "[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SettingsViewController" nib but the view outlet was not set."
SettingsViewController already has a view property. Are you sure this one is hooked up in Interface Builder? (You probably want it to be hooked up to your UITableView.)