How to combine several iOS controls in one entity (control)? - objective-c

I want to implement custom search and have one trouble. I need to combine UIButton, SearchBar in one control in order I can refer it by pointer.Then i will dynamically add more UIbuttons to that combined control.And the most important I want to manipulate this combined control as one program entity. For instance,CombinedControl* control;
So what the common way to implement this? Or may be I can emulate this?Thanks in advance!

If you're looking to combine multiple controls into a single unit, the simplest thing to do is just to add them as subviews of a single UIView. You can do this either in Interface Builder (by creating a blank UIView and dropping the other controls on it) or in code (using addSubview:). Then you just have a variable that points to the UIView that you added everything to.
If you want to add behavior to the "combined control", then you should create a subclass of UIView (as H2CO3 suggested above) and add the controls to that view subclass.

Related

Repeat a view in Cocoa application

I have the following design:
How should I proceed? Add a NSScrollView with the first element, which contains a couple of NSTextFields and an NSImage and then repeat in the code? What type of repeater should I use? And... is NSScrollView able to handle this type of design?
Is it possible to use NSTableView?
Thank you!
I would probably have a custom NSView class that contains the date labels on the left, a NSImage that toggles between two states (selected or not) and the request label on the right. You can lay it out either in code or in a .nib and instantiate it that way respectively.
When you create the superview create four of the new subclasses and put them in the appropriate places.
Only use scroll view if you think that you'll have so many options that you will need to scroll.

How to initiate display of one view from another?

Assume you do not have a UIController to do the job. From inside the UIView .. how would you replace self with another UIView?
It's not very clear what you are trying to do from your question. UIController is not a class, for instance.
Ideally your app should be structured something like this:
UIViewController subclass
Controls a set of objects that are all on screen at one time. For example, any number of UITextFields, UIButtons, UIViews and UILabels.
has methods (IBActions and other delegate methods) which are triggered by user interaction with the controls and inputs.
has IBOutlets which allow it to manipulate what the user sees on screen. For instance an IBOutlet attached to a UILabel allows changing the text when a user presses a button.
UIView is only generally subclassed if you need custom drawing code, or some kind of custom control. Don't put application logic here if you can help it, and you can usually help it.
You can have multiple UIViewControllers but they usually function very independently. Often View Controllers don't maintain references for other view controllers. If they do it's loose couplings like the delegate pattern.
Bottom line: if you have two views controllers that need to communicate with each-other, you need to have a reference to one from the other. This usually occurs in the form of a property on one or both of the view controllers, and is connected either by interface builder or at run time when you create them.
You can add another subview using self.addSubview: you may also want to check self.bringSubviewToFront:
For more information, check the docs:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

Best way to have UITableView within another table?

I have a grouped UITableView in class A and if you select a row in section 0, I want it to open up to another UITableView. In the first view, I have a lot of other methods and buttons and custom designed stuff, so I don't want to create another XIB for the other table view since I'll have to copy over all the methods and custom designed stuff. I was thinking creating another XIB, but subclassing the class under the original class A this way I can use the methods of class A without having to redefine them again in the new class. But I'm having problems with this. Is there a better way? Can I have two table views in one XIB, and just hide one till the other is called up? But that seems a little messy..
If you simply try subclassing the existing viewcontroller it will have the same info for the selected row, hence it would have to grow exponentially in order to make display the right UITableView.
If your concern is redefining methods, then simply create a class that will hold those particular methods and include it in the UITableViewControllers that will be using them, that way you will only define it once. This way you can simply create a new UITableViewController and push it into a navigation controller everytime you select a given cell.
As an alternative of showing all options within one UITableView you can try the following: you can probably try adding a UIScrollView inside the UITableViewCell. I would make it scroll horizontally while keeping the UITableView scroll vertically.

Cocoa Merging Custom Views

Currently, I have an NSStatusItem that, when clicked, shows a custom view below it. The view contains some information and text fields. What I need is for a separate custom view to merge with the first and appear below it, as in further down the screen, not on top or behind the original view. This needs to be a separate view because there are actually several custom view that will be appended depending on what the user does in the first view. I would like to be able to independently add or remove each of these without affecting the others. I've dug through apple documentation but I haven't found anything about putting one custom view inside another programatically.
NSView has an addSubview:positioned:relativeTo: method you can use to add and order views to appear above or below each other. Use superview: to access this method on a container from any of its subviews.
Edit:
Try adding both views to an NSSplitView with a hidden divider. To hide the divider, subclass NSSplitView and override the dividerThickness: method to return 0;

Custom Views or Custom Cells

I have a question about creating custom views. I wanted to implement an interface where I want to have different objects configured in one place, each of them with it's own controls. Kind of like in automator, on the right side view where the workflow is shown with different actions. Are those NSView or NSCell subclasses ?
Any example will be appreciated !
Ken
Here's how you can tell an NSCell and an NSView apart:
NSCells are basically stamps. Given a certain value/object, the NSCell knows how to draw that on the screen how you want it. Like NSTextCells know how to draw NSString's on the screen how you want them. NSCells don't have state, don't remember anything, they're just a one-shot set of drawing instructions that get executed with a given value/object. The idea is to reuse NSCells as much as possible to make drawing things on the screen super simple.
NSViews are sort of logical containers for what goes on on your screen. They can technically do their own drawing, but quite a few of them use NSCells to do their drawing. For example, NSTextField uses an NSTextCell to draw it's text on the screen, it also contains the extra logic necessary to toggle between editing and not-editing by displaying the text box you can type in during editing and using the NSTextCell when you're not editing. NSViews are also part of the responder chain and can respond to mouse-clicks, keyboard events, and the sort.
You're probably going to end up with both, NSViews to hold all the controls you want to use to configure each object and NSCells to draw custom UI elements (like if you use non-standard controls).