How to develop iOS app just like AppStore's searching function? - objective-c

I want to develop a simple dictionary application which is like the Search tab of AppStore on iPhone:
The 1st screen have a SeachBar on top, the bottom is "History words" (such as "Trending Searches" on AppStore).
When user touches the SearchBar, the bottom view is gray. Touching the gray area to leave the Seach text-box and my user is able to click on one of history words.
If he/she types on SearchBar, the suggestion words list appears and he/she can click a word to see its definition with the SearchBar containing the word there (I don't want my users having to go to 2nd view to see word's definition because if so, they must click Back button to touch and type on Seach text-box. It's likely that, my application has only 1 ViewController).
I know how to work with SearchBar and TableView to display the suggestion words list but don't know what to do to implement other things:
Make a view gray; touching on the gray area to leave the Search text-box
Hide the suggestion words list (TableView) -> user can see "History words" again
Keep the SearchBar -> user can type immediately to search other word when he/she is seeing current word definition
Thanks for reading and please show me some keywords, clues to solve three issues above.
Many thanks!

Use UISearchController to create a page like you wanted.
It has dimsBackgroundDuringPresentation property to make a backgroundView gray when user is typing.
It has - (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController method. You can initialize the UISearchController with resultsController. For results you can do whatever you want.
Lastly, you can set a custom view to see "History words" to UISearchController

Related

Adding A View To An Existing View Programatically

How can you add or replace a view within a view with code? I'm programming for OSX, not IOS.
I am using a drawer that utilizes a custom view. In the custom view I have two boxes, one with a custom set of icons that I want to stay static and another box that has the information related to that button. What I want to do is when a user clicks one of the buttons that the 2nd box view changes to reflect the info for that button.
For example, I have five buttons and the default 2nd box is "Info", if the user clicks the 2nd button in the first box view I want to change the 2nd box to be the "List" box instead while the 1st box with the buttons stays intact.
I'm not sure how this would impact constraints since while the first box is a fixed size, the 2nd box needs to be dynamic so that it fills in the "rest of the space" so that when the drawer size changes with the window size that the 2nd box is taking up the remaining real estate.
Thank you!
I have implemented such a scenario in the past using a tabless NSTabView, and an NSSegmentedControl (for the buttons). The NSTabView has it's -takeSelectedTabViewItemFromSender: action connected to the NSSegmentedControl, using Interface Builder.
In the Connections Inspector, this shows up like so:
This has the effect that the index of the selected NSTabViewItem in your NSTabView will correspond to the index of the selected segment in the NSSegmentedControl.

UIText field does not respond to touch after switching view

In my app, I have a text field that works fine, however after going back to the main menu and then back onto the page with the text field, the text field becomes un-touchable, the keyboard does not show no matter how many times you click it.
Here is a screen shot of the interface http://tinypic.com/view.php?pic=y11sm&s=6
I think I may have to add code or connect an action with the text field, but how?
Thanks for your time.
You can remove subviews that you don't use anymore like #Kim has already told you or if you need these subviews but they are blocking the action, you can bring your textfield to front using,
[your_view bringSubviewToFront: your_textfield];

How to prevent a UIView from consuming user input

I have a simple view hierarchy example.
Obviously the main view space is the primary space the user will interact with. At the bottom I have tabs that can pop up to indicate to the user where he/she is in the progression of the app. Normally, these tabs only take up the space indicated by the "Custom Tabs" rectangle at the bottom, but they can expand all the way up to fill the "Empty Space" box.
In order for the tabs to still be clickable, I had to make the tab view's frame the full rectangle containing both the "Custom Tabs" space and "Empty Space" space. What this results in is that "Empty Space" not being interactive to the user when the tabs aren't popped up, because the input is basically being consumed by that UIView, and not forwarded through the rest of the hierarchy.
I suppose the root of this problem is that both "Main View Space" and the "Empty Space + Custom Tabs" are both subviews of the main window.
Is there a way I can tell the system to forward the user input to the sibling views if the user didn't actively tap on an interactive element? For example, doing something with the touchesBegan, touchesEnded etc. methods that would indicate to the OS that this view did not use the input.
EDIT
Here's another version of the view, demonstrating the tate of one tab being open:
EDIT2
After some simple testing, it would seem that the default behavior is that the top most view gets the input first. This applies even if you have a clear UIView on top of a UITextField. The clear UIView will consume the input, preventing the UITextField from being editable
EDIT3
The way the tabs are supposed to work is the user can tap on a tab (sized as in the first picture), and then it will expand to display a thumbnail view associated with that tab (as in the second picture). The user can then optionally tap the tab once more to close it, and return the size to the original picture. In order for the tab to be clickable when it is open, I have to have the containing view be basically large enough to contain all 4 tabs as if they were open. This results in a lot of empty space in the containing view. This empty space results in essentially dead input space on the screen. If there were a button in the main view space that is covered by the empty space, the user would not be able to click on it. I would like to be able to avoid that behavior, and have that button covered by the empty space still be clickable.
Rather than trying to "forward" touches, I would modify your layout so that the tab view is only as big as the tabs, and change it's .frame to be the larger rectangle in code only when you need it. For example, when a tab is clicked:
CGRect tabFrame = tabView.bounds;
tabFrame.origin.y = top_of_emptySpace;
tabFrame.size.height = height_of_emptySpace + height_of_tabView;
tabView.frame = tabFrame;
then you can add the content you need. when you need it to go away, remove the content then do :
CGRect tabFrame = tabView.bounds;
tabFrame.origin.y = top_of_tabView;
tabFrame.size.height = height_of_tabView;
tabView.frame = tabFrame;
There might be some tweaking required to make the content show up as you like, but this way, when the tabs are minimized, you won't have to do anything extra to make the main view respond to touches correctly.
Ok, this is the way I would do it:
The RootViewController has two views, its main view which takes the whole screen, the one that is added to the window. And the tab view.
Then I would add another view controller (a UINavigationController ideally) to the RootViewController and I would have its view added as a subview of the RootViewController's view.
Any change performed, such as pushing new view controller or anything, would be done to the child view controller.
That way, your tab view would always be showing. To open a tab, you could create a new view that would show on top of the tab bar using an animation or something similar.

Table View Add Functionality?

I am new to the field of iOS development.
I have a tab bar application with four tabs, my second tab is a navigation controller which has a table on it when I press a cell it pushes to my detail view. My third tab is a favorite tab, and what I want is if I like anything in my table view how can I make that value go in the Favorite tab which might also have a table in it.
I want you ideas how can I do this ?
(Like should I have a button on the navigation bar "Add to Favourite" as soon as I click on that tab my table changes into edit mode with the "+" sign coming in front of every cell, the value I like I press the + sign and it goes in the favorite tab) this is what I thought but I really don't know how to implement it.
Can you help me out in this ?
This question's way too big for Stack Overflow. You should really go through Apple's sample code and documentation.
To get you started:
For the 4 tabs, you most likely want to embed everything in a UITabBarController, which will be your root view controller.
To get the edit mode functionality you're looking for, you're going to want to override - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath to enable that. (See UITableViewDelegate documentation).
Using the edit mode "+" button functionality as a way to add cells to a favorites list is non intuitive. Your users are going to be used to seeing that button in the Contacts app, etc, in the context of being used to add more fields or more information. They're not going to expect it to put things in a list in a different tab. See how Apple manages favorites in the contacts app for an example of how to do it right. You should also consult the Human Interface Guidelines.

How can I keep an NSPopUpButton open after the user selects a menu item?

I have an NSPopUpButton providing the NSMenu for a status item with a custom view. The popup button displays a list of links. When the user selects a link from the list, the link is displayed in the user's browser (in the background).
Naturally, the menu closes every time the user selects a link.
I would like to change this: I want the menu to stay open while the user clicks on various links, all of which can be opened in the background. The menu can then go away when the user clicks elsewhere.
How can this be accomplished? Should I subclass NSMenuItem and intercept the mouse clicks somehow? Overlay a transparent NSView on the popped-up menu and, again, intercept the clicks somehow? I make these suggestions blithely, but I would have trouble implementing either of these...pointers to the right methods for override would be appreciated.
Instead of using a menu, one might use a collapsible box.I have seen that in many apps ( also provided by Apple) , so I guess this is the recommended style guide for multiple selections.
The collapsible box expands when you click the disclosure button, and it gives free all items desired - like a tableview with checkboxes.
Views below this box must move down in this case, not to interfere with the box.
Clicking again on the disclosure button will shrink the box back to its origin. The effect is similar to closing a menu.
Usually you should not bend a control too far past it's original intent. Users expect pop up buttons to close after making a selection. I don't think you should, or can, force NSPopUpButtonCell to behave in this way. If you do, you'll be subclassing and modifying the control so heavily that it might change/break with a future version of Mac OS X. You'd also have to worry about the usability problem of users thinking the menu will close after making a selection.
You might consider writing you're own subclass of NSView to work like the menu button you're describing. After the user clicks on the button. You'll want to create a new NSWindow, with no border by using NSBorderlessWindowMask as the style mask. The content view of that window should be another custom view of yours that you implement the menu selection in.