I have a TableView that present a contact.
When I click the cell i would like to do straight to Editable view, instead of going to the CNContactViewController and press "edit Button".
Now i have the following :
firstview
secondview
I would like to skip the second step. Is that possible?
the code I'm using is the same from apple's:
let contacts = try contactStore.unifiedContactWithIdentifier
(contactIdentifier!, keysToFetch: toFetch)
let controller = CNContactViewController(forContact: contacts)
controller.contactStore = contactStore
controller.delegate = self
controller.editing = true
navigationController?
.pushViewController(controller, animated: true)
print(controller.editButtonItem())
} catch {
print(error)
}
EDIT: More or less, to illustrate, what Im trying to do, is the same as WhatsApp has in their App!, thanks!!
Have you tried this approach ?
let toFetch = [CNContactViewController.descriptorForRequiredKeys()]
let contacts = try contactStore.unifiedContactWithIdentifier
(contactIdentifier!, keysToFetch: toFetch)
let contactsViewController = CNContactViewController(forNewContact: contacts)
contactsViewController.delegate = self
contactsViewController.title = "Edit contact"
contactsViewController.contactStore = contactStore
self.navigationController?.pushViewController(contactsViewController, animated: true)
Related
I have an app that sends local notiffications at specific times. When the user taps on the notification, the app should open on a particular tab (a library tab) and then open automatically one of the lessons (without the user having to tap on it).
I can get the app to switch to the Library tab, but the modal with the lesson never appears.
This is the code I'm using:
if let tabBarController = window.rootViewController as? UITabBarController {
// this works
tabBarController.selectedViewController!.dismiss(animated: true, completion: nil)
tabBarController.selectedViewController = tabBarController.viewControllers?[1]
// Segue to particular lesson
let vc = tabBarController.selectedViewController as? LibraryViewController
let lessonVC = LessonViewController()
let les60 = Lesson(lessonNumber: "60")
lessonVC.delegate = vc
lessonVC.lesson = les60
vc?.present(UINavigationController(rootViewController: lessonVC), animated: true)
}
This is the code I use for every item in the Library:
let lessonVC = LessonViewController()
lessonVC.delegate = self
lessonVC.lesson = lessonsArray[indexPath.row]
present(UINavigationController(rootViewController: lessonVC), animated: true)
so I tried to replicate it above but it does not work.
I am using Pulley where I am using below code to open the PulleyViewController.
func openEventInfoPage(event : EventsModel,indexPath:NSIndexPath){
let vc = storyboard?.instantiateViewController(withIdentifier: "PulleyViewController")
as! PulleyViewController
navigationController?.pushViewController(vc, animated: true)
}
Here, while opening the PulleyViewController I also need to send data to both DrawerContentViewController and PrimaryContentViewController. How should I do that?
Its nowhere mentioned on Github, I tried making object of both the classes and sending data before Pushing PulleyViewController but it didn't work. Thanks in advance.
I came out with the following solution and it worked perfectly.
let mainContentVC = storyboard?.instantiateViewController(withIdentifier: "PrimaryContentViewController") as! PrimaryContentViewController
mainContentVC.event = event
mainContentVC.indexPath = indexPath
let drawerContentVC = storyboard?.instantiateViewController(withIdentifier: "DrawerContentViewController") as! DrawerContentViewController
drawerContentVC.event = event
let pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
navigationController?.pushViewController(pulleyDrawerVC, animated: true)
Add a property on DrawerContentViewController. like - aProperty as open property. And assign value of aProperty on your DrawerContentViewController -
func openEventInfoPage(event : EventsModel,indexPath:NSIndexPath){
let vc = storyboard?.instantiateViewController(withIdentifier: "PulleyViewController") as! PulleyViewController
let vc2 = storyboard?.instantiateViewController(withIdentifier: "DrawerContentViewController") as! DrawerContentViewController
vc2.aProperty = "value"
navigationController?.pushViewController(vc, animated: true)
}
I have been working on this problem for a bit but can't get anything to work.
I have a view controller that effectively stands along in the main story board. Inside that view controller, when a specific action occurs that passes a contact type to the action.
The action opens a new contact view controller for the contact passed, and allows the user to interact with the contact per the CNContactViewController.
Once the user is done with the contact, it will close, because of the didCompleteWith method, but there is no way to exit the contact controller, without actually creating the contact.
//change to new contact screen
let con = CNMutableContact()
con.givenName = familyComponents[0]
con.familyName = familyComponents[1]
let newEmail = CNLabeledValue(label: "Personal", value: objectComponents[2]
as NSString)
con.emailAddresses.append(newEmail)
con.phoneNumbers.append(CNLabeledValue(
label: "Home", value: CNPhoneNumber(stringValue: objectComponents[3])))
let newScreen = CNContactViewController(forUnknownContact: con)
newScreen.message = "Made using app"
newScreen.contactStore = CNContactStore()
newScreen.delegate = self
newScreen.allowsActions = true
let navigationController = UINavigationController(rootViewController:
newScreen)
self.present(navigationController, animated: true, completion: nil)
I have tried everything from navigationItems to navigationItems, it seems to me that the navigation bar is there, because it is possible to change its translucency with this line of code:
navigationController.navigationBar.isTranslucent = true
Methods Below:
func contactViewController(_ viewController: CNContactViewController,
didCompleteWith contact: CNContact?) {
viewController.dismiss(animated: true, completion: nil)
inContact = false
}
func contactViewController(_ shouldPerformDefaultActionForviewController:
CNContactViewController, shouldPerformDefaultActionFor property:
CNContactProperty) -> Bool {
return false
}
Any suggestions would be greatly appreciated, I have been struggling with this problem for too long.
Thanks!
SOLVED:
Got it to work. Turns out that this is a bug in apples framework. To solve this problem I just switched it from Unknown Contact to New Contact, which apparently does not have this bug.
Part of new code:
let newScreen = CNContactViewController(forNewContact: con)
newScreen.delegate = self
let navigationController = UINavigationController(rootViewController: newScreen)
self.present(navigationController, animated: true, completion: nil)
Thanks
can you try with this code
let con = CNMutableContact()
con.givenName = familyComponents[0]
con.familyName = familyComponents[1]
let newEmail = CNLabeledValue(label: "Personal", value: objectComponents[2]
as NSString)
con.emailAddresses.append(newEmail)
con.phoneNumbers.append(CNLabeledValue(
label: "Home", value: CNPhoneNumber(stringValue: objectComponents[3])))
let unkvc = CNContactViewController(forUnknownContact: con)
unkvc.delegate = self
unkvc.allowsEditing = true
unkvc.allowsActions = true
unkvc.title = "Edit Contact"
self.navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationItem.hidesBackButton = true
self.navigationController?.pushViewController(unkvc, animated: false)
I have a task to show the contact editing screen at once during his appearance (such as WhatsApp), I show him the following way.
#objc private func presentContactEditController() {
guard var contact = contactModel.contact else { return }
if !contact.areKeysAvailable([CNContactViewController.descriptorForRequiredKeys()]) {
do {
let contactStore = CNContactStore()
contact = try contactStore.unifiedContact(withIdentifier: contact.identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()])
} catch {
debugPrint("presentContactEditController error", error.localizedDescription)
}
}
let cnContactViewController = CNContactViewController(for: contact)
cnContactViewController.delegate = self
cnContactViewController.setEditing(true, animated: false)
let contactNaviController = UINavigationController(rootViewController: cnContactViewController)
present(contactNaviController, animated: true, completion: nil)
}
But there is a screen with information about this contact. So I tried to do it through the heir of CNContactViewController, different methods ViewController life cycle, but it works only in viewDidAppear method, but it will be visible to the user. How can I solve this problem? Thank you.
just change let cnContactViewController = CNContactViewController(for: contact)
to
let cvc = CNContactViewController(forNewContact: contact)
it will work for you
I came to the conclusion that that WhatsApp create a custom screen for this purpose. Just I saw the same screen in Telegram only with a modified design.
I'm working with Swift3. I have an App with the VCs as in the picture.
In the Mainmenu-VC the user triggers the Input-segue. User enters a firstname in the Input-VC. This triggers the Select-segue to Select-VC to select a surname and trigger Selected-segue to Details-VC.
From the Mainmenu-VC the user can also access the Details-VC. Back via NavigationControllerMechanism to Mainmenu-VC.
I want to change the NavigationControllerMechanism 'history', so that when the user enters from the Details-VC via the Selected-segue, the previous VC is changed from Select-VC to Mainmenu-VC.
So basically when in the Details-VC, the Back always returns to Mainmenu-VC.
I have tried combining various solutions from the web, without succes.
Is this possible?
Yes it is.
The View-Controller stack is stored in currentViewController.navigationController?.viewControllers.
So you should make something like :
//In Your Details VC :
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard let stack = self.navigationController?.viewControllers else { return }
//get the mainMenu VC
let mainVC = stack.first!
// Rearrange your stack
self.navigationController?.viewControllers = [mainVC, self]
//Now you can press "bac" to Main VC
}
you want to change navigation stack in this way you can manipulate
let myprofile = storyboard.instantiateViewController(withIdentifier: "Profile1ViewController") as! Profile1ViewController
let sourseStack = self.navigationController!.viewControllers[0];
var controllerStack = self.navigationController?.viewControllers
let index = controllerStack!.index(of: sourseStack);
controllerStack![index!] = myprofile
self.navigationController!.setViewControllers(controllerStack!, animated: false);
to go to RootViewController
dispatch_async(dispatch_get_main_queue(), {
self.navigationController?.popToRootViewControllerAnimated(true)
})