Presenting View Controllers from Other View Controllers
2014-11-02 14:29
253 查看
转自:https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Theabilitytopresentviewcontrollersisatoolthatyouhaveatyourdisposalforinterruptingthecurrentworkflowanddisplayinganewsetofviews.Mostcommonly,anapppresentsaviewcontrollerasatemporaryinterruptiontoobtainimportantinformation
fromtheuser.However,youcanalsousepresentedviewcontrollerstoimplementalternateinterfacesforyourappatspecifictimes.
Apresentedviewcontrollerisnotaspecificsubclassof
Instead,anyviewcontrollercanbepresentedbyyourapp.However,liketabbarandnavigationcontrollers,youpresentviewcontrollerswhenyouwanttoconveyaspecificmeaningabouttherelationshipbetweenthepreviousviewhierarchyandthenewlypresented
viewhierarchy.
Whenyoupresentamodalviewcontroller,thesystemcreatesarelationshipbetweentheviewcontrollerthatdidthepresentingandtheviewcontrollerthatwaspresented.Specifically,theviewcontrollerthat
didthepresentingupdatesits
topointtoitspresentedviewcontroller.Similarly,thepresentedviewcontrollerupdatesits
topointbacktotheviewcontrollerthatpresentedit.Figure10-1showstherelationshipbetweentheviewcontrollermanagingthemainscreenintheCalendar
appandthepresentedviewcontrollerusedtocreatenewevents.
Figure10-1PresentedviewsintheCalendar
app.
Anyviewcontrollerobjectcanpresentasingleviewcontrolleratatime.Thisistrueevenforviewcontrollersthatwerethemselvespresentedbyanotherviewcontroller.Inotherwords,youcanchainpresented
viewcontrollerstogether,presentingnewviewcontrollersontopofotherviewcontrollersasneeded.Figure10-2showsavisualrepresentationofthe
chainingprocessandtheactionsthatinitiateit.Inthiscase,whentheusertapstheiconinthecameraview,theapppresentsaviewcontrollerwiththeuser’sphotos.Tappingtheactionbuttoninthephotolibrary’stoolbarpromptstheuserforanappropriate
actionandthenpresentsanotherviewcontroller(thepeoplepicker)inresponsetothataction.Selectingacontact(orcancelingthepeoplepicker)dismissesthatinterfaceandtakestheuserbacktothephotolibrary.TappingtheDonebuttonthendismisses
thephotolibraryandtakestheuserbacktothecamerainterface.
Figure10-2Creatingachainofmodal
viewcontrollers
Eachviewcontrollerinachainofpresentedviewcontrollershaspointerstotheotherobjectssurroundingitinthechain.Inotherwords,apresentedviewcontrollerthatpresentsanotherviewcontrollerhas
validobjectsinbothits
Youcanusetheserelationshipstotracethroughthechainofviewcontrollersasneeded.Forexample,iftheusercancelsthecurrentoperation,youcanremoveallobjectsinthechainbydismissingthefirstpresentedviewcontroller.Dismissingaviewcontroller
dismissesnotonlythatviewcontrollerbutalsoanyviewcontrollersitpresented.
InFigure
10-2,apointworthnotingisthatthepresentedviewcontrollersarebothnavigationcontrollers.Youcanpresent
inthesamewaythatyouwouldpresentacontentviewcontroller.
Whenpresentinganavigationcontroller,youalwayspresentthe
anyoftheviewcontrollersonitsnavigationstack.However,individualviewcontrollersonthenavigationstackmaypresentotherviewcontrollers,includingothernavigationcontrollers.Figure
10-3showsmoredetailoftheobjectsthatareinvolvedintheprecedingexample.Asyoucansee,thepeoplepickerisnotpresentedbythephotolibrarynavigationcontrollerbutbyoneofthecontentviewcontrollersonitsnavigationstack.
Figure10-3Presentingnavigation
controllersmodally
ForiPadapps,youcanpresentcontentusingseveraldifferentstyles.IniPhoneapps,presentedviewsalwayscoverthevisibleportionofthewindow,butwhenrunningonaniPad,viewcontrollersusethevalue
intheir
determinetheirappearancewhenpresented.Differentoptionsforthispropertyallowyoutopresenttheviewcontrollersothatitfillsalloronlypartofthescreen.
Figure10-4showsthecorepresentationstylesthatareavailable.(The
letsaviewcontrolleradoptthepresentationstyleofitsparent.)Ineachpresentationstyle,thedimmedareasshowtheunderlyingcontentbutdonotallowtapsinthatcontent.Therefore,unlikeapopover,yourpresentedviewsmuststillhavecontrolsthat
allowtheusertodismisstheview.
Figure10-4iPadpresentationstyles
Forguidanceonwhentousethedifferentpresentationstyles,seeModal
ViewiniOSHumanInterfaceGuidelines.
Whenaviewcontrollerispresentedusingastoryboardsegue,itisautomaticallyinstantiatedandpresented.Thepresentingviewcontrollercanconfigurethedestinationviewcontrollerbeforeitispresented.
Formoreinformation,seeConfiguring
theDestinationControllerWhenaSegueisTriggered.
Ifyouneedtopresentaviewcontrollerprogrammatically,youmustdothefollowing:
Createtheviewcontrolleryouwanttopresent.
Setthe
theviewcontrollertothedesiredvalue.
Assignadelegateobjecttotheviewcontroller.Typically,thedelegateisthepresentingviewcontroller.The
delegateisusedbythepresentedviewcontrollerstonotifythepresentingviewcontrollerwhenitisreadytobedismissed.Itmayalsocommunicateotherinformationbacktothedelegate.
Callthe
ofthecurrentviewcontroller,passingintheviewcontrolleryouwanttopresent.
The
thepresenting-presentedrelationshipsbetweenthenewviewcontrollerandthecurrentviewcontroller.Unlessyouarerestoringyourapptosomepreviousstate,youusuallywanttoanimatetheappearanceofthenewviewcontroller.Thetransitionstyleyou
shouldusedependsonhowyouplantousethepresentedviewcontroller.Table10-1liststhetransitionstylesyoucanassigntothe
ofthepresentedviewcontrolleranddescribeshowyoumightuseeachone.
Table10-1Transitionstylesformodalviewcontrollers
Listing10-1showshowtopresentaviewcontrollerprogrammatically.Whentheuseraddsanewrecipe,the
apppromptstheuserforbasicinformationabouttherecipebypresentinganavigationcontroller.AnavigationcontrollerwaschosensothattherewouldbeastandardplacetoputaCancelandDonebutton.Usinganavigationcontrolleralsomakesiteasier
toexpandthenewrecipeinterfaceinthefuture.Allyouwouldhavetodoispushnewviewcontrollersonthenavigationstack.
Listing10-1Presentingaviewcontrollerprogrammatically
WhentheusertapseithertheDoneortheCancelbuttonfromthenewrecipeentryinterface,theappdismissestheviewcontrollerandreturnstheusertothemainview.SeeDismissing
aPresentedViewController.
Theareaofthescreenusedtodefinethepresentationareaisdeterminedbythepresentationcontext.Bydefault,thepresentationcontextisprovidedbytherootviewcontroller,whoseframeisusedtodefine
theframeofthepresentationcontext.However,thepresentingviewcontroller,oranyotherancestorintheviewcontrollerhierarchy,canchoosetoprovidethepresentationcontextinstead.Inthatcase,whenanotherviewcontrollerprovidesthepresentation
context,itsframeisusedinsteadtodeterminetheframeofthepresentedview.Thisflexibilityallowsyoutolimitthemodalpresentationtoasmallerportionofthescreen,leavingothercontentvisible.
Whenaviewcontrollerispresented,iOSsearchesforapresentationcontext.Itstartsatthepresentingviewcontrollerbyreadingits
Ifthevalueofthispropertyis
thenthepresentingviewcontrollerdefinesthepresentationcontext.Otherwise,itcontinuesupthroughtheviewcontrollerhierarchyuntilaviewcontrollerreturns
untilitreachesthewindow’srootviewcontroller.
Whenaviewcontrollerdefinesapresentationcontext,itcanalsochoosetodefinethepresentationstyle.Normally,thepresentedviewcontrollerdetermineshowitpresentedusingits
Aviewcontrollerthatsets
alsoset
If
setto
iOSusesthepresentationcontext’s
determinehowthenewviewcontrollerispresented.
Whenitcomestimetodismissapresentedviewcontroller,thepreferredapproachistoletthepresentingviewcontrollerdismissit.Inotherwords,wheneverpossible,thesameviewcontrollerthatpresented
theviewcontrollershouldalsotakeresponsibilityfordismissingit.Althoughthereareseveraltechniquesfornotifyingthepresentingviewcontrollerthatitspresentedviewcontrollershouldbedismissed,thepreferredtechniqueisdelegation.
Formoreinformation,seeUsing
DelegationtoCommunicatewithOtherControllers.
Anumberofstandardsystemviewcontrollersaredesignedtobepresentedbyyourapp.Thebasicrulesforpresentingtheseviewcontrollersarethesameastherulesforpresentingyourcustomcontentviewcontrollers.
However,becauseyourappdoesnothaveaccesstotheviewhierarchymanagedbythesystemviewcontrollers,youcannotsimplyimplementactionsforthecontrolsintheviews.Interactionswiththesystemviewcontrollerstypicallytakeplacethroughadelegate
object.
Eachsystemviewcontrollerdefinesacorrespondingprotocol,whosemethodsyouimplementinyourdelegateobject.Eachdelegateusually
implementsamethodtoeitheracceptwhateveritemwasselectedorcanceltheoperation.Yourdelegateobjectshouldalwaysbereadytohandlebothcases.Oneofthemostimportantthingsthedelegatemustdoisdismissthepresentedviewcontrollerbycalling
the
oftheviewcontrollerthatdidthepresenting(inotherwords,theparentofthepresentedviewcontroller.)
Table10-2listsseveralofthestandardsystemviewcontrollersfoundiniOS.Formoreinformationabout
eachoftheseclasses,includingthefeaturesitprovides,seethecorrespondingclassreferencedocumentation.
Table10-2Standardsystemviewcontrollers
Note:Althoughthe
intheMediaPlayerframeworkmighttechnicallybethoughtofasamodalcontroller,thesemanticsforusingitareslightlydifferent.Insteadofpresentingtheviewcontrolleryourself,youinitializeitandtellittoplayitsmediafile.Theviewcontroller
thenhandlesallaspectsofpresentinganddismissingitsview.(However,the
canbeusedinsteadof
PresentingViewControllersfromOtherViewControllers
Theabilitytopresentviewcontrollersisatoolthatyouhaveatyourdisposalforinterruptingthecurrentworkflowanddisplayinganewsetofviews.Mostcommonly,anapppresentsaviewcontrollerasatemporaryinterruptiontoobtainimportantinformationfromtheuser.However,youcanalsousepresentedviewcontrollerstoimplementalternateinterfacesforyourappatspecifictimes.
HowViewControllersPresentOtherViewControllers
Apresentedviewcontrollerisnotaspecificsubclassof(asUIViewController
UITabBarControlleror
UINavigationControlleris).
Instead,anyviewcontrollercanbepresentedbyyourapp.However,liketabbarandnavigationcontrollers,youpresentviewcontrollerswhenyouwanttoconveyaspecificmeaningabouttherelationshipbetweenthepreviousviewhierarchyandthenewlypresented
viewhierarchy.
Whenyoupresentamodalviewcontroller,thesystemcreatesarelationshipbetweentheviewcontrollerthatdidthepresentingandtheviewcontrollerthatwaspresented.Specifically,theviewcontrollerthat
didthepresentingupdatesits
propertypresentedViewController
topointtoitspresentedviewcontroller.Similarly,thepresentedviewcontrollerupdatesits
propertypresentingViewController
topointbacktotheviewcontrollerthatpresentedit.Figure10-1showstherelationshipbetweentheviewcontrollermanagingthemainscreenintheCalendar
appandthepresentedviewcontrollerusedtocreatenewevents.
Figure10-1PresentedviewsintheCalendar
app.
Anyviewcontrollerobjectcanpresentasingleviewcontrolleratatime.Thisistrueevenforviewcontrollersthatwerethemselvespresentedbyanotherviewcontroller.Inotherwords,youcanchainpresented
viewcontrollerstogether,presentingnewviewcontrollersontopofotherviewcontrollersasneeded.Figure10-2showsavisualrepresentationofthe
chainingprocessandtheactionsthatinitiateit.Inthiscase,whentheusertapstheiconinthecameraview,theapppresentsaviewcontrollerwiththeuser’sphotos.Tappingtheactionbuttoninthephotolibrary’stoolbarpromptstheuserforanappropriate
actionandthenpresentsanotherviewcontroller(thepeoplepicker)inresponsetothataction.Selectingacontact(orcancelingthepeoplepicker)dismissesthatinterfaceandtakestheuserbacktothephotolibrary.TappingtheDonebuttonthendismisses
thephotolibraryandtakestheuserbacktothecamerainterface.
Figure10-2Creatingachainofmodal
viewcontrollers
Eachviewcontrollerinachainofpresentedviewcontrollershaspointerstotheotherobjectssurroundingitinthechain.Inotherwords,apresentedviewcontrollerthatpresentsanotherviewcontrollerhas
validobjectsinbothits
andpresentingViewController
properties.presentedViewController
Youcanusetheserelationshipstotracethroughthechainofviewcontrollersasneeded.Forexample,iftheusercancelsthecurrentoperation,youcanremoveallobjectsinthechainbydismissingthefirstpresentedviewcontroller.Dismissingaviewcontroller
dismissesnotonlythatviewcontrollerbutalsoanyviewcontrollersitpresented.
InFigure
10-2,apointworthnotingisthatthepresentedviewcontrollersarebothnavigationcontrollers.Youcanpresent
objectsUINavigationController
inthesamewaythatyouwouldpresentacontentviewcontroller.
Whenpresentinganavigationcontroller,youalwayspresentthe
UINavigationControllerobjectitself,ratherthanpresenting
anyoftheviewcontrollersonitsnavigationstack.However,individualviewcontrollersonthenavigationstackmaypresentotherviewcontrollers,includingothernavigationcontrollers.Figure
10-3showsmoredetailoftheobjectsthatareinvolvedintheprecedingexample.Asyoucansee,thepeoplepickerisnotpresentedbythephotolibrarynavigationcontrollerbutbyoneofthecontentviewcontrollersonitsnavigationstack.
Figure10-3Presentingnavigation
controllersmodally
PresentationStylesforModalViews
ForiPadapps,youcanpresentcontentusingseveraldifferentstyles.IniPhoneapps,presentedviewsalwayscoverthevisibleportionofthewindow,butwhenrunningonaniPad,viewcontrollersusethevalueintheir
propertytomodalPresentationStyle
determinetheirappearancewhenpresented.Differentoptionsforthispropertyallowyoutopresenttheviewcontrollersothatitfillsalloronlypartofthescreen.
Figure10-4showsthecorepresentationstylesthatareavailable.(The
styleUIModalPresentationCurrentContext
letsaviewcontrolleradoptthepresentationstyleofitsparent.)Ineachpresentationstyle,thedimmedareasshowtheunderlyingcontentbutdonotallowtapsinthatcontent.Therefore,unlikeapopover,yourpresentedviewsmuststillhavecontrolsthat
allowtheusertodismisstheview.
Figure10-4iPadpresentationstyles
Forguidanceonwhentousethedifferentpresentationstyles,seeModal
Viewin
PresentingaViewControllerandChoosingaTransitionStyle
Whenaviewcontrollerispresentedusingastoryboardsegue,itisautomaticallyinstantiatedandpresented.Thepresentingviewcontrollercanconfigurethedestinationviewcontrollerbeforeitispresented.Formoreinformation,seeConfiguring
theDestinationControllerWhenaSegueisTriggered.
Ifyouneedtopresentaviewcontrollerprogrammatically,youmustdothefollowing:
Createtheviewcontrolleryouwanttopresent.
Setthe
propertyofmodalTransitionStyle
theviewcontrollertothedesiredvalue.
Assignadelegateobjecttotheviewcontroller.Typically,thedelegateisthepresentingviewcontroller.The
delegateisusedbythepresentedviewcontrollerstonotifythepresentingviewcontrollerwhenitisreadytobedismissed.Itmayalsocommunicateotherinformationbacktothedelegate.
Callthe
methodpresentViewController:animated:completion:
ofthecurrentviewcontroller,passingintheviewcontrolleryouwanttopresent.
The
presentViewController:animated:completion:methodpresentstheviewforthespecifiedviewcontrollerobjectandconfigures
thepresenting-presentedrelationshipsbetweenthenewviewcontrollerandthecurrentviewcontroller.Unlessyouarerestoringyourapptosomepreviousstate,youusuallywanttoanimatetheappearanceofthenewviewcontroller.Thetransitionstyleyou
shouldusedependsonhowyouplantousethepresentedviewcontroller.Table10-1liststhetransitionstylesyoucanassigntothe
propertymodalTransitionStyle
ofthepresentedviewcontrolleranddescribeshowyoumightuseeachone.
Transitionstyle | Usage |
---|---|
| Usethisstylewhenyouwanttointerruptthecurrentworkflowtogatherinformationfromtheuser.Youcanalsouseittopresentcontentthattheusermightormightnotmodify. Forthisstyleoftransition,contentviewcontrollersshouldprovidebuttonstodismisstheviewcontrollerexplicitly.Typically,theseareaDonebuttonandanoptionalCancelbutton. Ifyoudonotexplicitlysetatransitionstyle,thisstyleisusedbydefault. |
| Usethisstyletochangetheworkmodeofyourapptemporarily.Themostcommonusageforthisstyleistodisplaysettingsthatmightchangefrequently,suchasintheStocksandWeatherapps.Thesesettingscanbemeantfortheentireapportheycanbespecific tothecurrentscreen. Forthisstyleoftransition,youusuallyprovidesomesortofbuttontoreturntheusertothenormalrunningmodeofyourapp. |
| Usethisstyletopresentanalternateinterfacewhenthedevicechangesorientations.Insuchacase,yourappisresponsibleforpresentinganddismissingthealternateinterfaceinresponsetoorientationchangenotifications. Media-basedappscanalsousethisstyletofadeinscreensdisplayingmediacontent. Foranexampleofhowtoimplementanalternateinterfaceinresponsetodeviceorientationchanges,seeCreating anAlternateLandscapeInterface. |
apppromptstheuserforbasicinformationabouttherecipebypresentinganavigationcontroller.AnavigationcontrollerwaschosensothattherewouldbeastandardplacetoputaCancelandDonebutton.Usinganavigationcontrolleralsomakesiteasier
toexpandthenewrecipeinterfaceinthefuture.Allyouwouldhavetodoispushnewviewcontrollersonthenavigationstack.
Listing10-1Presentingaviewcontrollerprogrammatically
-(void)add:(id)sender{ |
//Createtherootviewcontrollerforthenavigationcontroller |
//ThenewviewcontrollerconfiguresaCancelandDonebuttonforthe |
//navigationbar. |
RecipeAddViewController*addController=[[RecipeAddViewControlleralloc] |
init]; |
//ConfiguretheRecipeAddViewController.Inthiscase,itreportsany |
//changestoacustomdelegateobject. |
addController.delegate=self; |
//Createthenavigationcontrollerandpresentit. |
UINavigationController*navigationController=[[UINavigationControlleralloc] |
initWithRootViewController:addController]; |
[selfpresentViewController:navigationControlleranimated:YEScompletion:nil]; |
} |
aPresentedViewController.
PresentationContextsProvidetheAreaCoveredbythePresentedViewController
Theareaofthescreenusedtodefinethepresentationareaisdeterminedbythepresentationcontext.Bydefault,thepresentationcontextisprovidedbytherootviewcontroller,whoseframeisusedtodefinetheframeofthepresentationcontext.However,thepresentingviewcontroller,oranyotherancestorintheviewcontrollerhierarchy,canchoosetoprovidethepresentationcontextinstead.Inthatcase,whenanotherviewcontrollerprovidesthepresentation
context,itsframeisusedinsteadtodeterminetheframeofthepresentedview.Thisflexibilityallowsyoutolimitthemodalpresentationtoasmallerportionofthescreen,leavingothercontentvisible.
Whenaviewcontrollerispresented,iOSsearchesforapresentationcontext.Itstartsatthepresentingviewcontrollerbyreadingits
property.definesPresentationContext
Ifthevalueofthispropertyis
,YES
thenthepresentingviewcontrollerdefinesthepresentationcontext.Otherwise,itcontinuesupthroughtheviewcontrollerhierarchyuntilaviewcontrollerreturns
orYES
untilitreachesthewindow’srootviewcontroller.
Whenaviewcontrollerdefinesapresentationcontext,itcanalsochoosetodefinethepresentationstyle.Normally,thepresentedviewcontrollerdetermineshowitpresentedusingits
property.modalTransitionStyle
Aviewcontrollerthatsets
todefinesPresentationContext
canYES
alsoset
toprovidesPresentationContextTransitionStyle
.YES
If
isprovidesPresentationContextTransitionStyle
setto
,YES
iOSusesthepresentationcontext’s
tomodalPresentationStyle
determinehowthenewviewcontrollerispresented.
DismissingaPresentedViewController
Whenitcomestimetodismissapresentedviewcontroller,thepreferredapproachistoletthepresentingviewcontrollerdismissit.Inotherwords,wheneverpossible,thesameviewcontrollerthatpresentedtheviewcontrollershouldalsotakeresponsibilityfordismissingit.Althoughthereareseveraltechniquesfornotifyingthepresentingviewcontrollerthatitspresentedviewcontrollershouldbedismissed,thepreferredtechniqueisdelegation.
Formoreinformation,seeUsing
DelegationtoCommunicatewithOtherControllers.
PresentingStandardSystemViewControllers
Anumberofstandardsystemviewcontrollersaredesignedtobepresentedbyyourapp.Thebasicrulesforpresentingtheseviewcontrollersarethesameastherulesforpresentingyourcustomcontentviewcontrollers.However,becauseyourappdoesnothaveaccesstotheviewhierarchymanagedbythesystemviewcontrollers,youcannotsimplyimplementactionsforthecontrolsintheviews.Interactionswiththesystemviewcontrollerstypicallytakeplacethroughadelegate
object.
Eachsystemviewcontrollerdefinesacorrespondingprotocol,whosemethodsyouimplementinyourdelegateobject.Eachdelegateusually
implementsamethodtoeitheracceptwhateveritemwasselectedorcanceltheoperation.Yourdelegateobjectshouldalwaysbereadytohandlebothcases.Oneofthemostimportantthingsthedelegatemustdoisdismissthepresentedviewcontrollerbycalling
the
methoddismissModalViewControllerAnimated:
oftheviewcontrollerthatdidthepresenting(inotherwords,theparentofthepresentedviewcontroller.)
Table10-2listsseveralofthestandardsystemviewcontrollersfoundiniOS.Formoreinformationabout
eachoftheseclasses,includingthefeaturesitprovides,seethecorrespondingclassreferencedocumentation.
Framework | Viewcontrollers |
---|---|
AddressBookUI |
|
EventKitUI |
|
GameKit |
|
MessageUI |
|
MediaPlayer |
|
UIKit |
|
classMPMoviePlayerController
intheMediaPlayerframeworkmighttechnicallybethoughtofasamodalcontroller,thesemanticsforusingitareslightlydifferent.Insteadofpresentingtheviewcontrolleryourself,youinitializeitandtellittoplayitsmediafile.Theviewcontroller
thenhandlesallaspectsofpresentinganddismissingitsview.(However,the
classMPMoviePlayerViewController
canbeusedinsteadof
MPMoviePlayerControllerasastandardviewcontrollerforplayingmovies.)
相关文章推荐
- Presenting View Controllers from Other View Controllers
- iOS自定义转场动画无法用presentingViewControll(fromView)中的view问题
- Presenting view controllers on detached view controllers is discouraged
- iOS:编译问题Presenting view controllers on detached view controllers is discouraged
- xocde8打印出:Presenting view controllers on detached view controllers is discouraged <SettingViewContro
- Presenting view controllers on detached view controllers is discouraged 我碰到这类问题的解决方法
- iOS 关于Presenting view controllers on detached view controllers is discouraged的警告
- Presenting view controllers on detached view controllers is discouraged
- 2.16 Presenting Multiple View Controllers with UITabBarController
- Presenting view controllers on detached view controllers is discouraged
- How View Controllers Present Other View Controllers
- iOS:编译问题Presenting view controllers on detached view controllers is discouraged
- Presenting view controllers on detached view controllers is discouraged
- xocde8打印出:Presenting view controllers on detached view controllers is discouraged
- Presenting view controllers on detached view controllers is discouraged
- Presenting view controllers on detached view controllers is discouraged
- Partial view from other controller
- Presenting view controllers on detached view controllers is discouraged <CallViewController: 0x14676e240>.
- Presenting view controllers on detached view controllers is discouraged
- 解决警告Presenting view controllers on detached view controllers is discouraged 以及引申