Saturday, 15 January 2011

ios - How to properly segue between view controllers -



ios - How to properly segue between view controllers -

so i've run problem while trying in objective-c , swift. new xcode bear me. create view controller (vc1), embed navigation controller , create new view controller (vc2). then, set button on vc1, , command drag vc2. run app , fine , dandy, clicking on button force new view controller onto stack , pressing button take me back. however, 1 time proceed add together new buttons , text fields vc2, app crash 1 time press original button on vc1, citing first line of app delegate file breakpoint. i've tried many things, namely trying code segue using self.performseguewithidentifier method not work. using xcode 6. in advance.

storyboard.swift (file vc1):

import uikit class storyboard: uiviewcontroller { @iboutlet var titlelabel : uilabel @iboutlet var orlabel : uilabel override func viewdidload() { super.viewdidload() } @ibaction func weightedaveragebuttonpressed(sender : anyobject) { self.performseguewithidentifier("weightedaverage1", sender: self) } @ibaction func whatineedbuttonpressed(sender : anyobject) { } }

weightedaverage.swift (vc2)(i've commented out rid of crash, no luck):

import uikit class weightedaverage: uiviewcontroller { /* @iboutlet var weightaveragetitlelabel : uilabel @iboutlet var percentagetocalclabel : uilabel @iboutlet var percentagelabel : uilabel @iboutlet var percentageinput : uitextfield @ibaction func continuebutton(sender : anyobject) { //var percent = percentageinput.text // percentagelabel.text = percent }*/ }

appdelegate.swift:

import uikit @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: nsdictionary?) -> bool { homecoming true } func applicationwillresignactive(application: uiapplication) { // sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone phone call or sms message) or when user quits application , begins transition background state. // utilize method pause ongoing tasks, disable timers, , throttle downwards opengl es frame rates. games should utilize method pause game. } func applicationdidenterbackground(application: uiapplication) { // utilize method release shared resources, save user data, invalidate timers, , store plenty application state info restore application current state in case terminated later. // if application supports background execution, method called instead of applicationwillterminate: when user quits. } func applicationwillenterforeground(application: uiapplication) { // called part of transition background inactive state; here can undo many of changes made on entering background. } func applicationdidbecomeactive(application: uiapplication) { // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface. } func applicationwillterminate(application: uiapplication) { // called when application terminate. save info if appropriate. see applicationdidenterbackground:. } }

here debug output says (when i've commented out ibaction method):

2014-06-19 12:29:12.471 gradecalc[13217:580024] -[_ttc9gradecalc10storyboard weightedaveragebuttonpressed:]: unrecognized selector sent instance 0x10bb0ad30 (lldb)

it highlights line of app delegate origin in "class appdelegate...."

when uncomment method contains performsegue... method output log says "(lldb)" , still highlights line of app delegate

have tried removing manual ibaction code button , using segue made on storyboard? may trying segue twice simultaneously if both used storyboard , class file it.

edit: code in working illustration 2 view controllers

first view controller:

class oneviewcontroller: uiviewcontroller { @iboutlet var label1: uilabel @iboutlet var label2: uilabel override func viewdidload() { super.viewdidload() // additional setup after loading view. }

second view controller:

class twoviewcontroller: uiviewcontroller { @iboutlet var upperlabel: uilabel @iboutlet var lowerlabel: uilabel @iboutlet var textbox: uitextfield @ibaction func button(sender: anyobject) { var percent = textbox.text lowerlabel.text = percent } override func viewdidload() { super.viewdidload() }

can't add together image due nda, storyboard navigationcontroller>vc1>vc2, 2 labels in each vc, text box in vc2, , button in each. sec button has action in vc class.

ios swift

No comments:

Post a Comment