UIPageController Dots Not Working When Clicked - ios

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.)

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.

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

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.

How to make Popup via storyboard(xib?) and programmatically Xamarin.iOS

For some reason i want to know how exactly i can implement Popup in Xamarin.iOS via storyboard and programmatically.
At current moment, i'm doing pretty simple workaround:
Inside designer, i'm dropping additional view(as popup) and configure like that
MyPopupView.Hidden = true;
After some steps(nvm), i'm showing this popup via
MyPopupView.Hidden = false;
And the result is :
Yeah, that is bad and very poor approach, because what if need these 5 guys or more ?
I will not be able to design my ViewController, because it will be stuffed with these views.
Also, for some reason i want to show arrow(see img below) and shadow(outside of popup) for better usability.
That what is exactly i want to do :
or this one(but inside, i want to put for e.g. my xib or VC,where i can drop some other views, like .gif animation):
or this one:
and finally, what i want(this one is amazing) :
Main idea to use storyboard(to make life easy with working on constraints and autolayout),but maybe it can be done programmatically the same.
I think that is possible to do that with UIAlertController , just needs to insert our View , but dunno is that right approach.
Thanks for any advice.
The last two images you posted can be accomplished using storyboards.
Essentially what you to do is create a separate scene/view controller in your storyboard and set it's presentation property to "over current context".
Alternatively you can set the segue to "Show modally" and the presentation property of the segue to "over current context" in Xcode
(for some reason the "Over current context" option doesn't come up in Xamarin Studio (at least not in Xamarin Studio 6) and when you open it back up in XS it will display a "Error while creating this entry" message by the presentation property but it should still work).
The next step is to set the root view to be transparent (background color = clear color) and then have a child view with your content.
If you want the semi-transparent overlay affect then what you can do is have two "sibling" child views one with your content (same as before) and a second view which is constrained to the edges of the root view and has it's alpha property set to something less then 1.
And here's the result...

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!

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.

Resources