Why can't I attach an action to the new Sign In With Apple ASAuthorizationAppleIDButton in a Storyboard? - ios

I'm working on a new codebase that has everything laid out in storyboards and I'm trying to implement the new ASAuthorizationAppleIDButton button as part of the new Sign In With Apple feature.
Reading online it looks like I can add a UIButton to the view and then override the class to be ASAuthorizationAppleIDButton. Easy enough. The weird parts comes when I try and wire that button up to an action in the VC. I can't do it. Even if I go the other way and drag from the button to the VC, the action item is missing from the connection menu.
Has anyone had success adding and interacting with this button from a storyboard? I'd prefer not to redo the entire view just because of this one issue.

ASAuthorizationAppleIDButton is not a button but its a control. And this is stated in that way to avoid misuse of this as a button. And only one action is associated with it which cannot be override. The only control you get is to use the delegate method of
didCompleteWithAuthorization & didCompleteWithError.
So if you want to use/include some extra selector or methods. you can add those in these delegate- methods.

Related

Passing data between more than 2 viewcontrollers in Swift

My app contains TabBar controller with 5 viewcontrollers. It is possible to click on a button in each of viewcontrollers which will popup another view in which user can choose a setting. The button (which was clicked) is supposed to change its background according to chosen setting in each viewcontroller. So if the user clicks on button in VC1 and chooses the setting, this information should spread into all of the other VCs so that the button has the same background.
I am using storyboards, and I know that this is easily possible between 2VCs using segues, protocols, closures... I cannot find a proper way to spread information to more than 2VCs.
The only solution I can think of is usage of UserDefaults. I would save an information about a button setting and then call ViewWillAppear in each VC, where the background of the button would be set according to the value in UserDefaults. Is there a better solution, please?
EDIT:
As #cora mentioned in the comments, I was able to solve this using Notification Center.
You have several options, including:
Pass an array of the tab controllers to your "popup settings" controller and call a "settingSelected" func in each one directly.
Using Protocol / Delegate pattern, you could create an array of delegates in your "popup settings" controller.
You can use Notification Center.
You could subclass the button and use UIAppearance proxy.
Which approach to use will depend on a number of factors, based on exactly what all you need to do (are there other "settings"? or only that button background?)
You may want to search for swift using themes to see various different approaches.
“Is there a better solution, please?”
Not necessarily. Is this in fact a user default, to be preserved between launches? Then this is exactly what user defaults are for.
If not, then at least you need some central location where information about the current button color can be stored. An obvious candidate here is the tab bar controller itself. It gets notified every time there is a tab bar item switch, so it’s a perfect candidate.
Since you have mentioned you are using a UITabbarController, you can use an instance of UITabbarController and then access .viewControllers property of it and call their added public methods to get them triggered on events that you add. Additionally, using Notification Center makes more sense to me since your code will be more readable. Sometimes Notifications can just get a little confusing for new developers who are working on your code.

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

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.

UIPageController Dots Not Working When Clicked

I have 2 viewControllers that i switch between using a UIPageController. Everything works fine and the dots switch correctly to the right controller, but when clicked they don't do anything.
I'm using a container view to have the dots in the middle of the screen and using delegation to update them.
Everything is set up using storyboards. If I try to connect value changed it doesn't get touch events, same thing if I try to set the action programmatically.
Don't "use delegation to update them". Implement the data source methods presentationCountForPageViewController: and presentationIndexForPageViewController:, and the UIPageViewController automatically creates a page control where updating and tapping both "just work".
(Otherwise, if you try to use an independent page control, you'll have to implement your own Value Changed event handler for it; it won't do anything by itself.)

Popup notification box

Im trying to create a popup style notification, which is shown at the top of the screen (using a basic animation). The notification is going to be a simple form with a submit button.
Im trying to figure out how to go about this, and what are the best options i have. I've found this popup library: https://www.cocoacontrols.com/controls/cqmfloatingcontroller
What are the best options for 1. creating the popup and 2. animating to popup
If this is something that you will be reusing a lot, it might be worth subclassing UIAlertView, as you can then automatically use all "popup" methods provided by it,and by customizing it's view you can get the appearance you want.

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)

Resources