将UITextField文本发送到另一个视图

时间:2016-04-24 00:23:50

标签: ios swift

当我想将UITextField的文本发送到另一个视图时遇到了问题。在调试时,它会一直运行到prepareForSegue函数结束,并且不会发生错误。

我不知道“无法识别的选择器发送到实例0x7f9272d996d0”是什么意思。你能解释一下吗?

以下是全班:

class ViewController: UIViewController, UITextFieldDelegate {


@IBOutlet var searchText: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    searchText.clearButtonMode = UITextFieldViewMode.WhileEditing

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let symbol: String = self.searchText.text!
    print(symbol) // this print function works
    let detail:DetailController = segue.destinationViewController as! DetailController
    detail.symbol = symbol

}

}

以下是异常输出。

2016-04-23 17:15:41.648 stockSearch[51526:12944707] -[stockSearch.ViewController searchTextfield:]: unrecognized selector sent to instance 0x7f9272d996d0
2016-04-23 17:15:41.653 stockSearch[51526:12944707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[stockSearch.ViewController searchTextfield:]: unrecognized selector sent to instance 0x7f9272d996d0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102a4fd85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001047f3deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000102a58d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010299ecfa ___forwarding___ + 970
    4   CoreFoundation                      0x000000010299e8a8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000103279a8d -[UIApplication sendAction:to:from:forEvent:] + 92
    6   UIKit                               0x00000001033ece67 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00000001033ed143 -[UIControl _sendActionsForEvents:withEvent:] + 327
    8   UIKit                               0x0000000103c766c5 -[UITextField _resignFirstResponder] + 298
    9   UIKit                               0x000000010348ba1a -[UIResponder _finishResignFirstResponder] + 292
    10  UIKit                               0x0000000103c764ef -[UITextField _finishResignFirstResponder] + 49
    11  UIKit                               0x000000010348bb3b -[UIResponder resignFirstResponder] + 254
    12  UIKit                               0x0000000103c763bc -[UITextField resignFirstResponder] + 136
    13  UIKit                               0x000000010348cf70 -[UIResponder _resignIfContainsFirstResponder] + 270
    14  UIKit                               0x00000001033207c4 -[UIView(Hierarchy) _willMoveToWindow:] + 597
    15  UIKit                               0x000000010332ec9e -[UIView(Internal) _addSubview:positioned:relativeTo:] + 481
    16  UIKit                               0x000000010325f9c8 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_2 + 2217
    17  UIKit                               0x0000000103327680 +[UIView(Animation) performWithoutAnimation:] + 65
    18  UIKit                               0x000000010325f0bd __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 270
    19  UIKit                               0x000000010332d82b +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
    20  UIKit                               0x000000010325eb02 -[_UINavigationParallaxTransition animateTransition:] + 1465
    21  UIKit                               0x00000001034492d9 -[UINavigationController _startCustomTransition:] + 4156
    22  UIKit                               0x0000000103458b9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    23  UIKit                               0x0000000103459d0b -[UINavigationController __viewWillLayoutSubviews] + 57
    24  UIKit                               0x0000000103608503 -[UILayoutContainerView layoutSubviews] + 248
    25  UIKit                               0x0000000103332980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
    26  QuartzCore                          0x0000000107896c00 -[CALayer layoutSublayers] + 146
    27  QuartzCore                          0x000000010788b08e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    28  QuartzCore                          0x000000010788af0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    29  QuartzCore                          0x000000010787f3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    30  QuartzCore                          0x00000001078ad086 _ZN2CA11Transaction6commitEv + 486
    31  UIKit                               0x000000010327272e _UIApplicationHandleEventQueue + 7135
    32  CoreFoundation                      0x0000000102975301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    33  CoreFoundation                      0x000000010296b22c __CFRunLoopDoSources0 + 556
    34  CoreFoundation                      0x000000010296a6e3 __CFRunLoopRun + 867
    35  CoreFoundation                      0x000000010296a0f8 CFRunLoopRunSpecific + 488
    36  GraphicsServices                    0x0000000106c7ead2 GSEventRunModal + 161
    37  UIKit                               0x0000000103277f09 UIApplicationMain + 171
    38  stockSearch                         0x00000001023fee52 main + 114
    39  libdyld.dylib                       0x00000001052b792d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

0 个答案:

没有答案