我是一个iOS菜鸟,很抱歉。
我提出了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.
}
}
答案 0 :(得分:2)
可以使用iOS模拟器进行设置。 转到iOS模拟器 - &gt;硬件 - &gt;键盘 - &gt;取消选择&#34;连接硬件键盘&#34;或选择&#34;切换软件键盘&#34;。