clicking search bar doesn't promp keypad (iOS Swift)

tim peterson

I'm a Swift noob, so sorry for the easy question.

I think I haven't attached the correct events for my search bar as when I click in it, the keyboard doesn't appear.

In the storyboard, I'm pretty sure I have to set the outlet for the UISearchBar's delegate to be the View Controller. But from this screenshot, it looks like the delegate is simply to the view. this screenshot

Here's my viewController.swift file, can someone help spot the error?

//
//  ViewController.swift
//  PhotoSearchExample
//
//  Created by Tim Peterson on 10/30/14.
//  Copyright (c) 2014 Tim Peterson. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UISearchBarDelegate {

    @IBOutlet weak var scrollView: UIScrollView!

    //@IBOutlet weak var searchString: UISearchBar!

    let instagramClientID = "xxxx"

    func searchInstagramByHashtag(searchString: String) {
        for subview in self.scrollView.subviews {
            subview.removeFromSuperview()
        }

        let instagramURLString = "https://api.instagram.com/v1/tags/" + searchString + "/media/recent?client_id=" + instagramClientID

        let manager = AFHTTPRequestOperationManager()

       self.scrollView.alpha = 0.0

        let activityIndictorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
        activityIndictorView.center = self.view.center
        self.view.addSubview(activityIndictorView)
        activityIndictorView.startAnimating()

        manager.GET( instagramURLString,
            parameters: nil,
            success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
                println("JSON: " + responseObject.description)

                if let dataArray = responseObject.valueForKey("data") as? [AnyObject] {
                    self.scrollView.contentSize = CGSizeMake(320, CGFloat(320*dataArray.count))
                    for var i = 0; i < dataArray.count; i++ {
                        let dataObject: AnyObject = dataArray[i]
                        if let imageURLString = dataObject.valueForKeyPath("images.standard_resolution.url") as? String {
                            println("image " + String(i) + " URL is " + imageURLString)



                            let imageView = UIImageView(frame: CGRectMake(0, CGFloat(320*i), 320, 320))
                            self.scrollView.addSubview(imageView)
                            imageView.setImageWithURL( NSURL(string: imageURLString))

                            activityIndictorView.stopAnimating()

                            UIView.animateWithDuration(1.0, animations: {
                                self.scrollView.alpha = 1.0
                                }, completion: {
                                    (value: Bool) in
                                    println("Animation complete!")
                            })

                        }
                    }
                }
            },
            failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
                println("Error: " + error.localizedDescription)
        })
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar!) {

        //println("search bar clicked!")

        searchBar.resignFirstResponder()
        searchInstagramByHashtag(searchBar.text)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

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

}
Craig Grummitt

You're on the right track Tim - you seem to have somehow set up your View as the delegate of your searchbar rather than the View Controller. I would recommend:

  1. Delete the connection in your Connections inspector.
  2. Open your Document Outline in the Interface Builder(button at the bottom left of Interface Builder)
  3. Now it's clearer what exactly you're dragging to - control drag from the searchbar directly to the ViewController, select delegate, and you should see it appear correctly in the Connections Inspector.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iOS 7 Search Bar - Cancel button doesn't work

From Dev

iOS 7 Search Bar - Cancel button doesn't work

From Dev

iOS Swift : UITableView KeyPad overlay

From Dev

iOS 7 doesn't show cancel button of search bar in navigation bar

From Dev

iOS 7 doesn't show cancel button of search bar in navigation bar

From Dev

swift ios adding search bar to picker view

From Java

Search Bar doesn't register input

From Dev

GNOME 3 search bar doesn't work

From Dev

UISearchController search bar doesn't get focus

From Dev

GNOME 3 search bar doesn't work

From Dev

Search bar doesn't display table after one search

From Dev

View doesn't change when clicking a row - xcode ios

From Dev

How to prevent search bar from disappearing on scroll? iOS Swift

From Dev

iOS Search Bar in Navigation Bar

From Dev

Search bar works correctly but table doesn't show the results

From Dev

Why doesn't empty() work on input in search bar?

From Dev

Xcode simulator keypad doesn't appear after using keyboard

From Dev

Xcode simulator keypad doesn't appear after using keyboard

From Dev

SearchView doesn't capture "ENTER" from keyboard or keypad

From Java

Tags in Search Bar with Swift

From Dev

search bar controller in swift

From Dev

iOS search bar displace

From Dev

Can't set search bar with search bar display color iOS7

From Dev

Can't change search bar tint color to be transparent in iOS 8

From Dev

Swift-iOS program doesn't run

From Java

navigation bar drawer menu doesn't close after clicking menu item

From Dev

Right clicking the top bar of Google Chrome doesn't show the default context menu

From Dev

iOS Swift - Filtering contents of UITableView that has custom cell with Search Bar and Search Display

From Dev

iOS 7 UIViewController (with navigation bar) doesn't inset UIScrollView

Related Related

  1. 1

    iOS 7 Search Bar - Cancel button doesn't work

  2. 2

    iOS 7 Search Bar - Cancel button doesn't work

  3. 3

    iOS Swift : UITableView KeyPad overlay

  4. 4

    iOS 7 doesn't show cancel button of search bar in navigation bar

  5. 5

    iOS 7 doesn't show cancel button of search bar in navigation bar

  6. 6

    swift ios adding search bar to picker view

  7. 7

    Search Bar doesn't register input

  8. 8

    GNOME 3 search bar doesn't work

  9. 9

    UISearchController search bar doesn't get focus

  10. 10

    GNOME 3 search bar doesn't work

  11. 11

    Search bar doesn't display table after one search

  12. 12

    View doesn't change when clicking a row - xcode ios

  13. 13

    How to prevent search bar from disappearing on scroll? iOS Swift

  14. 14

    iOS Search Bar in Navigation Bar

  15. 15

    Search bar works correctly but table doesn't show the results

  16. 16

    Why doesn't empty() work on input in search bar?

  17. 17

    Xcode simulator keypad doesn't appear after using keyboard

  18. 18

    Xcode simulator keypad doesn't appear after using keyboard

  19. 19

    SearchView doesn't capture "ENTER" from keyboard or keypad

  20. 20

    Tags in Search Bar with Swift

  21. 21

    search bar controller in swift

  22. 22

    iOS search bar displace

  23. 23

    Can't set search bar with search bar display color iOS7

  24. 24

    Can't change search bar tint color to be transparent in iOS 8

  25. 25

    Swift-iOS program doesn't run

  26. 26

    navigation bar drawer menu doesn't close after clicking menu item

  27. 27

    Right clicking the top bar of Google Chrome doesn't show the default context menu

  28. 28

    iOS Swift - Filtering contents of UITableView that has custom cell with Search Bar and Search Display

  29. 29

    iOS 7 UIViewController (with navigation bar) doesn't inset UIScrollView

HotTag

Archive