0

Hello I am new with swift and sorry if my code is a mess.

I want to control web view with bin and text field.I mean i want to do some thing that if i put the correct word in text field and click Button the button check the value and if the value is correct the web view show me the site or the link i gave it to.thanks

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textfield: UITextField!
    @IBOutlet weak var web: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }  

    @IBAction func Btn(sender: AnyObject) {

        if textfield.text == "Nature" {
            let requestnature = NSURLRequest(URL: NSURL(string: "https://www.google.com/imgres?imgurl=https%3A%2F%2Fwallpapercave.com%2Fwp%2Fu9AVLry.jpg&imgrefurl=https%3A%2F%2Fwallpapercave.com%2Fnature-wallpaper&docid=KHA0yQyMDxoeLM&tbnid=PSHFXiArDFPVBM%3A&vet=10ahUKEwi01Z_NkoTkAhUJ_KQKHSYbCqkQMwh7KAMwAw..i&w=1920&h=1080&hl=en&bih=635&biw=1239&q=nature%20wallpaper&ved=0ahUKEwi01Z_NkoTkAhUJ_KQKHSYbCqkQMwh7KAMwAw&iact=mrc&uact=8")!)
            web.loadRequest(requestnature)
        }     
    }   
}

2019-08-14 23:07:19.508 Download app[781:9061] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Txtfield.' * First throw call stack: ( 0 CoreFoundation 0x0000000101393e65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001030d6deb objc_exception_throw + 48 2 CoreFoundation 0x0000000101393aa9 -[NSException raise] + 9 3 Foundation 0x000000010175d9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x0000000101d41320 -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000101f6ff41 -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x00000001012d44a0 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit 0x0000000101f6e924 -[UINib instantiateWithOwner:options:] + 1864 8 UIKit 0x0000000101d47eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x0000000101d48816 -[UIViewController loadView] + 178 10 UIKit 0x0000000101d48b74 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x0000000101d492e7 -[UIViewController view] + 27 12 UIKit 0x0000000101c1fab0 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x0000000101c20199 -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x0000000101c31c2e -[UIWindow makeKeyAndVisible] + 42 15 UIKit 0x0000000101baa663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 16 UIKit 0x0000000101bb0cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760 17 UIKit 0x0000000101bade7b -[UIApplication workspaceDidEndTransaction:] + 188 18 FrontBoardServices 0x0000000104f9c754 -[FBSSerialQueue _performNext] + 192 19 FrontBoardServices 0x0000000104f9cac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 20 CoreFoundation 0x00000001012bfa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 21 CoreFoundation 0x00000001012b595c __CFRunLoopDoSources0 + 556 22 CoreFoundation 0x00000001012b4e13 __CFRunLoopRun + 867 23 CoreFoundation 0x00000001012b4828 CFRunLoopRunSpecific + 488 24 UIKit 0x0000000101bad7cd -[UIApplication _run] + 402 25 UIKit 0x0000000101bb2610 UIApplicationMain + 171 26 Download app 0x00000001011b132d main + 109 27 libdyld.dylib 0x0000000103be692d start + 1 28 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

2 Answers 2

1

Bad Outlet.

You have either removed or renamed an outlet name in your controller. Remove it in .storyboard file's Connection Inspector.

Sign up to request clarification or add additional context in comments.

Comments

0

This looks like you might have tried to create an outlet previously for your UITextField but mis-spelled it, in interface builder if you right click on the textfield you should see the outlet connections, there is possibly two, one which is mis-spelled and broken.

Remove this outlet reference and try again and see if that resolves your issue.

Or you may have made the outlet connection and then noticed the typo and just corrected it in code. In this case remove the outlet and add it again. You can CTRL drag from either the IBOutlet in code to the button or vice versa to create the outlet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.