Add a view before master detail - xcode

I have made an app using the Master-Detail Application template, and I have realised that I need to have a view before the table view. How do I do this, because I have tried to create a view then setting the Main Interface to the new view, and I just get SigBRT...
How can I do this?
Thanks in advance,
Rafee

Please create a project that use UIViewController (or drag it by yourself from object library). Then follow this steps:
1) Drag tableView into storyboard, place it in view controller that belongs to your UIViewController;
2) Add protocols in header of your class. Put it in interface line like this - #interface YourViewController : UIViewController
3) Add property to header of your class - #property (strong, nonatomic) IBOutlet UITableView *tableView;
4) Control+drag tableView on storyboard and connect it to DataSource and tableView delegate,and connect it to property IBOutlet UITableView *tableView;
5) Add cells, reuse identifiers to tableView, and class methods to implementation of your class.

Related

UIButton and UILabel not showing up on device screen

I have a UILabel and UIButton in my Xib interface builder. The 600x600 screen says what I'll dragging+dropping on is a View.
When I drag and drop the label and button onto the view, and make them IBOutlet properties, they seem to not be part of any view hierarchy.
#property (retain, nonatomic) IBOutlet UILabel *label;
#property (retain, nonatomic) IBOutlet UIButton *button;
They each have their own respective constraints.
Here's two images.
Interface Builder
Interface Builder Outlet
I have synthesized both properties. Do I need to do anything programmatically? I thought Interface builder took care of everything, which is why I ask. The class in question is a custom subclass of a UIViewController, so do I need to drag and drop on to a view controller instead?

How to link ibOutlet from subview to custom UIView Class in storyboard xcode

I think this image explains it all. I have a subclass of UIView that I've entered into the class field. I'm trying to connect ibOutlets between the storyboard and class implementation. It's not giving me an error, but it's not working either. Is this another xcode bug, or am I expecting this to work in a way that it won't?
Here is a solution:
1) Type an IBOutlet by hands in your header file, example:
#property (strong, nonatomic) IBOutlet ProgressBarElementView *targetProgressElement;
2) Drag the pin from the code to the element in document outline zone
I have the same problem.. I saw that if you add the custom class to the root view in the view controller, it will work.. In your case this is the initial View, listed under Bottom Layout Guide
But there must be a better way
To overcome XCode stubborness, especially when you need to hook up different enums from UIControlEvent than UIControlEventTouchUpInside, I'd rather use code directly from within the custom view class:
SWIFT
button.addTarget(self, action:#selector(ClassName.handleRegister(sender:)),
for: .touchDragExit)
OBJECTIVE-C
[self.button addTarget:self
action: #selector(buttonTouchDragExitAction:)
forControlEvents:UIControlEventTouchDragExit];
One might include such code in awakeFromNib or viewDidLoad or where it best suits.
write the outlet inside your custom UIView
#IBOutlet weak var imageView: UIImageView!
then drag it into the storyboard on the view

Can't CTRL+Drag NSButton to custom NSView header

I'd like to create a custom NSTableCellView instantiated by Interface Builder. I've set my Table Cell View class to MyTableCellView, and properly created MyTableCellView : NSTableCellView .m/.h files.
However, I just can't CTRL+Drag a simple button from inside this view to MyTableCellView.h in order to create an IBOutlet.
Here is a video to show what happens: http://youtu.be/sNNbuVT-SZs.
How the view is subclassed:
How I try to CTRL+Drag a button
Also, sometimes, Interface Builder just don't allow the cell view's class to be modified. What's happening ?
I finally found a solution, that is a little weird but works as expected. Instead of connecting the NSButton to MyTableCellView header directly, I used the reversed path:
Manually create an outlet:
#property(retain, nonatomic) IBOutlet NSButton* button;
Then click the empty circle on the left, and drag it to your XIB file's button:
I have no idea why it works this way, please let me know if you know the anwser.

Why is my UIView not the "parent" of my UIImageView?

I have an mainUIView within which there is a customised UIImageView (named myImageView).
In the myImageView.h file, I have declared:
#property (strong, nonatomic) mainViewController *viewController;
and in the myImageView.m file, I have the following codes:
self.viewController = self.parent;
This lines raises an error indication:
Property 'parent' not found on object of type myImageView.
I thought putting the myImageView inside the mainUIView would make the default parent-and-sub relationship, but obviously it's not so.
In the main storyboard, I tried to Ctrl-drag the myImageView to the mainViewController, but no options pops up for me to select delegate.
Can anyone give me explanation of these please? I'm feeling a bit confused... Many thanks!
As your myImageView is a UIView is has no parent. Is just has a superview which again is a UIView. Basically a view doesn't know its controller. Although the controller can implement a view's delegate to get informed about events. So your AppDelegate knows your ViewController and the controller knows your ImageView. The AppDelegates window knows the view of your controller which will most likely contain the whole view hierarchy (except AlertViews, HUDViews, modal views and simmilar...).
I think what you want to do works best implementing the delegate pattern. (see Apple Docs)

Uitableview within uiview

I have Uitable view within uiview with navigation bar , I want to add button to the navigation bar to edit the contents of uitableview
any suggestion how to do that please
I think that you want to place your UITableView controller within a UINavigationController (see the UINavigationController class reference for more information).
In your UIViewController for the UITableView, you need to override the methods found under the "Configuring a Navigation Interface" section of the Apple Developer Documentation.
Within this section of methods lies - (UIBarButtonItem *)editButtonItem, which you could override to provide the button for your editing purpose. Under the hood, the UINavigationController will call this method to get the edit button for its user interface. Using this technique ensures that your app stays consistant with the user expierence iOS users have come to love.
There is solution that I tried and worked for me. The solution is
in .h file
UIBarButtonItem *edit;
and set property line as
#property (nonatomic , retain) IBOutlet UIbarButtonItem *edit;
in .m file
in your action handler of the button add
[self.tableView setEditing:TRUE];
Open the .xib file of your view controller and add a UIBarButtonItem either to left or right side of the Navigation Bar and connect the respective IBOutlet to edit button and also the selector method.
Now in the delgate of tableView add the following method
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//sets the editing style for every row.
return UITableViewCellEditingStyleDelete;
}
Now you can play around with the UITableViewDelegate Methods and also the above methos to get the desired functionality.
Hope it works and do communicate if it does!!

Resources