How to make a floating/3D Touch style tableview? - ios

So i'm making an application for tracking livestock. I have made a table view for the animals to go in. I have a navigation controller at the top with a button in side of it.Here is what i have so far.
I would like to have a floating table view come up when the button is pressed similar to the 3D touch menu.
Like these.
My question is how would i go about doing this. Sorry if this is a commonly done thing im pretty new to swift and xcode

If you just wanna to implement,you could search the key words as 'pop over', 'kxmenu' or 'menu' on GitHub/CocoaControls. such like this: https://github.com/zpz1237/NirKxMenu https://github.com/liufengting/FTPopOverMenu
Also, you should make it yourself. When the button is pressed, first you should create a custom window and make it key window. Secondly, add a tableView or a view contains tableView to the custom window. then, use block or delegate to deal with data communication and respond user interaction. After that, design animation you need. At last, remove subviews from custom window and make the original window key window.

Related

Custom Keyboard Accessory view input

I have created a custom accessory view to supplement the standard Apple alpha iOS keyboard.
The purpose is to add a line of numeric keys to prevent flipping back and forth between keyboard views. At first, I created a toolbar and loaded it with a set of 0 - 9 titled buttonItems and it functioned quite well. However, it looked terrible, not at all like the alpha keys despite adding a rounded rect background image to each key because the system apparently prevents customizing font size and button spacing inside the stack view of the toolbar. Therefore, I created a UIView xib and loaded it with a stackView full of customized numerical buttons. When I add the UIView as the accessory view it looks pretty darn close to the rest of the Apple Alpha keyboard. The issue now is that the touch-up events go to the UIView class of the accessory view. Is there a clever, efficient way to have the button presses in the accessory emulate the std keyboard feeding into TextField: shouldChangeCharactersIn? I could package the button presses into a local notification event to get it into the class holding the textField but that seems terribly inelegant! Any suggestions would be greatly appreciated. Stay Safe!
Not the best answer, but I did implement notification on key button press with an observer in the main view class. The observer does a TextField.insertText which is suboptimal since I will need to refactor the several hundred lines of code that performs real-time language translation in the shouldChangeCharacters methods. Ah well.

Using single UIView I want to manage tap action based on location and update specific object

enter image description here
I am making app like sudoku (9*9 boxes) but it has only binary choices (on/off) and using button gave me horrible results. Can anyone give me demo version of 9*9 (or 3*3) box where depending upon the tap location, that specific box gets toggled (on/off)
You could create a custom subclass of UIView that had an attached tap gesture recognizer and interpreted the tap location to figure out which cell is being tapped, but it would be a lot of work.
It would be better to have custom view that contains a grid of buttons and set up the button actions to do what you want.
You said "...using button gave me horrible results." Can you elaborate? That should be a good way to go, so any "horrible results" are likely the result of something you did wrong, rather than that being the wrong way to go.

How do I make the elements in my UIView responsive?

My goal is to create an alert that has three text fields, one taller than the others, and an image that, when tapped, allows the user to choose a picture to replace a set default one.
After unsuccessfully searching for a library for this, I decided to create my own alert by placing a UIView off the screen and, when prompted by a button, would zoom onto the screen; it consists of all the elements I require.
When I run the application, the view pops up correctly, but none of the elements on the view are responding to touch. I've checked that isUserInteractionEnabled for everything is turned on.
What's also odd is that when I keep the view on the screen (instead of placing it some distance away on Storyboard), all the elements work fine.
I'm assuming it had something to do with the animation. I tested it with a fade in instead of a displacement, and the result was the same - the elements were unresponsive.
In order for your elements to be responsive you have to link the action of you clicking them to your view's code. You can do this in a non-programmatic manner by ctrl-clicking your element on story-views and then dragging to the view controller. Then choose action instead of outlet, and choose when the action you want will be triggered (bottom part). Then insert your code in the viewController.
So I figured it out. I used the debug view hierarchy and saw that the alert was behind the elements behind it, even though it was still being shown (for some reason). I changed the zIndex of the UIView and it worked!

Enable editing mode for tableView when button is pressed

This has probably been asked before but I'm new to iOS Development and when I found confused me. I have a tableView and want to allow the user to tap a button that says "Edit" and they can delete items. I also want the edit button to become a "Done" button, which will stop edit mode. (The user can add data into the tableView from another option, which I will probably need to research how to do.) I don't have a storyboard as I built the app in an app called Interface. Everything is all in code.
The UIViewController class provides a method that gives you the standard Edit/Done button. You can do something like:
self.navigationItem.rightBarButtonItem = [self editButtonItem];
This standard button is setup to call the setEditing:animated: method. When used with a UITableViewController, the table view is automatically toggled between regular and edit mode along with the view controller.
There are plenty of specific table view delegate and data source methods you need to implement on top of this to facilitate actual table editing but using this standard button at least easily lets you toggle in and out of editing mode.
You will need to add the UITableViewDelegate methods.
I presume the 'Done'/'Edit' Button is the same in some place such as your UINavigationBar?
You will have to manually change the title for the button.
Remember to set your ViewController as the delegate for tableview too.
This delegate method informs that you wish to have the table eidtable.
– tableView:editingStyleForRowAtIndexPath:
This method tells you you will start editing:
– tableView:willBeginEditingRowAtIndexPath:
(hint: change button title here)
Likewise this tells you editing is done:
– tableView:didEndEditingRowAtIndexPath:
(hint: change button title here)

What are the "First Responder" and "Exit" boxes purpose in the storyboard editor?

In the XCode IDE, at the bottom of the view controller in the MainStoryboard editor, are two boxes: First Responder, and Exit.
I know what a firstResponder is programatically within the code, but in the storyboard editor, I can't seem to do anything useful by it.
Am I able to use the first responder in this area to somehow set the first responder of the view? I'd like the first textfield to be active on load and I have tried right+click and dragging to no avail. I know I can set it programatically in the viewDidLoad method, but is there some way of doing it here?
And what is the green Exit for?
There are no good answer for this question, so I am posting my answer:
From here:
Note: You probably won’t be using the First Responder very much. This is a proxy object that refers to whatever object has first responder status at any given time. It was also present in your nibs and you probably never had a need to use it then either. As an example, you can hook up the Touch Up Inside event from a button to First Responder’s cut: selector. If at some point a text field has input focus then you can press that button to make the text field, which is now the first responder, cut its text to the pasteboard.
Edit:
1) First Responder is very useful if you are using text fields with keyboard notifications. I use it to make keyboard disappear, make an outlet to variable currentFirstResponder of your class, and in viewWillDisappear:
[self.currentFirstResponder resignFirstResponder];
2) You can read about unwind segues ("Exit" box) here
I've never used it and probably never will but you can assign an object to be the first in line to receive the events from the UI.
I suppose you could be creating a UIView subclass and add it in to a UIViewController but you actually want some other object to receive and process the events other than the UIViewController you are adding it to.
I found this link which kind of explains it a bit better.
First Responder: The First Responder icon stands for the object that the user is currently interacting with. When a user works with an iOS application, multiple objects could potentially respond to the various gestures or keystrokes that the user creates. The first responder is the object currently in control and interacting with the user. A text field that the user is typing into, for example, would be the first responder until the user moves to another field or control.
Exit: The Exit icon serves a very specific purpose that will come into play only in multiscene applications. When you are creating an app that moves the user between a series of screens, the Exit icon provides a visual means of jumping back to a previous screen. If you have built five scenes that link from one to another and you want to quickly return to the first scene from the fifth, you’ll link from the fifth scene to the first scene’s Exit icon.
More here
You don't see this very often, where a deleted answer is actually correct, and the comment (likely influencing its deletion) on it is totally wrong! I'll try and improve on it.
Usually the IBAction you want to hook up to a button is in the view controller containing the button. However if the IBAction is in a different controller, e.g. a parent controller then drag from the button to the First Responder object and you are able to select the IBAction in the parent controller!
As the hidden answer states, how this is implemented is the action is sent to nil, which has the effect of the responder chain (i.e. view hierarchy) being searched for the action, as follows:
[UIApplication.sharedApplication sendAction:#selector(nextObject:) to:nil from:self forEvent:nil];
An example is a custom UITableViewCell. Add a UIButton to the cell but you want the action to go up to a View Controller that has an embed segue to a UITableViewController. Drag the touch up instead action to the First Responder and select the action in the container view controller. In the action to find the indexPath simply loop the visibleCells and check if the sender is isDescendantOfView:
- (IBAction)cellButtonTapped:(id)sender{
for(UITableViewCell *cell in self.tableViewController.tableView.visibleCells){
if([sender isDescendantOfView:cell]){
NSIndexPath *indexPath = [self.tableViewController.tableView indexPathForCell:cell];
NSLog(#"tapped %#", indexPath);
}
}
}
Another example could be a reload button: say your first view controller shows an downloaded item with an IBAction to reload it to get the latest data, then your child controller shows some detail, but you also want them to be able to reload the main item from within the detail, just add a button in the detail and drag its action to First Responder and select the reload IBAction in the parent controller. This allows you to hook up buttons to parent actions with no additional code like delegate methods!
For this to work the action needs to be in the responder chain hierarchy or it won't be found, you can read how the chain is built up in the docs. Also note if called from code the view needs to have appeared, viewWillAppear is too soon.

Resources