2014-11-01 51 views
0

我是iOS的noob,很抱歉。點擊搜索欄不會打開小鍵盤(iOS Swift)

我做a sample Search app (full code here)有當我點擊搜索欄的問題,它不會打開小鍵盤

誰能幫助?

這是我的viewController.swift文件:

// 
// 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! 

    let instagramClientID = "xxxxxx" 

    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. 
    } 

} 

回答

2

它可以與iOS模擬器設置。 轉到iOS模擬器 - >硬件 - >鍵盤 - >取消選擇「連接硬件鍵盤」或選擇「切換軟件鍵盤」。

+0

你是對的!謝謝,很酷! – 2014-11-01 18:57:48