trying wrap head around issue i'm facing. want press button , share url via share sheet. here have far:
import uikit class sidemenu: uiview { //share app @ibaction func shareappbtn(sender: anyobject ) { print("shareappbtn tapped") let mywebsite = nsurl(string:"http://www.google.com/") guard let url = mywebsite else { print("nothing found") return } let shareitems:array = [url] let activityviewcontroller:uiactivityviewcontroller = uiactivityviewcontroller(activityitems: shareitems, applicationactivities: nil) self.presentviewcontroller(activityviewcontroller, animated: true, completion: nil) } }
which gave me following error: value of type 'sidemenu' has no member 'presentviewcontroller'
. think above doesn't work because presentviewcontroller component of uiviewcontroller , i'm calling uiview.
so instead tried following, attempting call uiviewcontroller:
import uikit class sidemenu: uiview { //share app @ibaction func shareappbtn(sender: anyobject, viewcontroller : uiviewcontroller) -> void { print("shareappbtn tapped") let mywebsite = nsurl(string:"http://www.google.com/") guard let url = mywebsite else { print("nothing found") return } let shareitems:array = [url] let activityviewcontroller:uiactivityviewcontroller = uiactivityviewcontroller(activityitems: shareitems, applicationactivities: nil) viewcontroller.presentviewcontroller(activityviewcontroller, animated: true, completion: nil) } }
but above gave me following error: unrecognized selector sent instance 0x7fe93acb6720'
.
so tried with:
import uikit class sidemenu: uiview { //share app @ibaction func shareappbtn(sender: anyobject) { print("shareappbtn tapped") let mywebsite = nsurl(string:"http://www.google.com/") guard let url = mywebsite else { print("nothing found") return } let shareitems:array = [url] let activityviewcontroller:uiactivityviewcontroller = uiactivityviewcontroller(activityitems: shareitems, applicationactivities: nil) self.window?.rootviewcontroller?.presentviewcontroller(activityviewcontroller, animated: true, completion: nil) } }
but above gave me following error:
warning: attempt present <uiactivityviewcontroller: 0x7fe03e04c600> on <ramanimatedtabbarcontroller.ramanimatedtabbarcontroller: 0x7fe03bc4a170> presenting <sidemenu.uisidemenunavigationcontroller: 0x7fe03c094200>
what missing here? want call share sheet on uiview.
thanks.
this working expected.. uiviews aren't supposed presenting views. should reporting delegates handle that.
in case of sidemenu
, uiview, you'd need delegate handle it's doing... e.g. set view controller presents sidemenu delegate..
so using bit of example code whipped up..
protocol sidemenudelegate { func sidemenudidshare() }
the delegate protocol view controller handles sidemenu view implement.
class sidemenu: uiview { var delegate: sidemenudelegate? }
in sidemenu view class, you'd add delegate property.
class sidemenuviewcontroller: uiviewcontroller, sidemenudelegate { func sidemenudidshare() { print("this share code goes , can present other viewcontrollers from") } override func viewdidload() { super.viewdidload() let sidemenu = self.view as? sidemenu sidemenu?.delegate = self } }
in view controller handles sidemenu, you'd implement sidemenudelegate protocol e.g. class sidemenuviewcontroller: uiviewcontroller, sidemenudelegate
doing allows sidemenu tell it's delegate (the viewcontroller) when happens, in case, implemented func sidemenudidshare()
.
Comments
Post a Comment