Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue when i try present CRNotifications #3

Closed
adelbios opened this issue Jun 21, 2017 · 7 comments
Closed

issue when i try present CRNotifications #3

adelbios opened this issue Jun 21, 2017 · 7 comments

Comments

@adelbios
Copy link

u've issue when i try display CRNotifications

in this class CRNotifications

UIApplication.shared.keyWindow?.rootViewController.view.addSubview(view)
but i fix it .....

adding parms
showNotification(type: CRNotificationType, title: String, message: String, dismissDelay: Int , viewController : UIViewController )

because when i try implement pushView controller or segue
the CRNotifications Displayed in the previous VC

so... viewController.view.addSubview(view)

it's work

@dkcas11
Copy link
Owner

dkcas11 commented Jun 26, 2017

It sounds like you are doing something wrong.

When calling the show() method it presents the notification on the current ViewController. If you need to show a notification as soon as you have pushed or used a segue to a new VC, you need to call the show() method in that VC's viewDidAppear.

@adelbios
Copy link
Author

i try but didn't work

@adelbios
Copy link
Author

i mean i try pushed

@sshahidaslamm
Copy link

sshahidaslamm commented Jul 5, 2017

@adelbios I have fixed this problem.
Actually the problem is the CRnotification adding the view into root view and when you have Navigation controller or tab-bar controller this notification is not appearing on screen with following code:
UIApplication.shared.keyWindow?.rootViewController?.view.addSubview(view)

You should replace following with the above one to work
UIApplication.shared.keyWindow?.addSubview(view)

I think @dkcas11 you should have to update this in library as well.

@adelbios
Copy link
Author

adelbios commented Jul 5, 2017

oK thanks but i fix it before 5 days

@dkcas11
Copy link
Owner

dkcas11 commented Jul 6, 2017

@adelbios @sshahidaslamm

The problem doesn't lie with the way the view is presented.

The UIApplication object holds a list of UIWindows which have a UIViewController (their "parent"). So, in order to add something, you go to the ViewController and fetch it's view and add whatever you like there. Adding it to the UIWindow itself may be dangerous and this ensures that the view actually is there.

I just tested this from the example project, where i added a NavigationController to the ViewController class, a button to the View, made a new UIViewController class and added a segue to this, from the button. In the newly added class, i ran the show() method from viewDidAppear... Worked perfectly fine. I also just ran the pushViewController directly when the button was pushed (which is the same as the segue does) and it also worked as intended.

Clearly, something is wrong with how you do it, adelbios. Could you provide me with the code of how you do this? And possibly a short outline of your setup.

Just to show you my code, here is the PushViewController class i made:

class PushViewController: UIViewController {

	override func viewDidLoad() {
		super.viewDidLoad()
	}
	
	override func viewDidAppear(_ animated: Bool) {
		super.viewDidAppear(animated)
		
		CRNotifications.showNotification(type: .success, title: "Pushed through!", message: "I'm right here.", dismissDelay: 3)
	}	

}

And the execution of my push, which is as trivial as it gets:

@IBAction func nextViewControllerButton(_ sender: Any) {
	navigationController?.pushViewController(PushViewController(), animated: true)
}

@adelbios
Copy link
Author

adelbios commented Jul 7, 2017

i wanna contact you... give me u're Email

@dkcas11 dkcas11 closed this as completed Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants