我的tableview标题中有一个搜索栏.为此,我正在使用uisearchcontroler.但是当我在搜索栏中发短信时它会更新tablview数据,我需要在点击键盘上的搜索按钮时更新tablview,因为我在api中获取搜索数据,每次当我在搜索栏中发短信时它都会请求并且需要很长时间.我怎么解决这个问题?
var resultSearchController = UISearchController()
var indicator:UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
var ref=UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = view.center
view.addSubview(indicator)
indicator.bringSubviewToFront(view)
indicator.startAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
getRequests.getType1(tableView,spinner: indicator)
ref.addTarget(self, action: #selector(Catalog1TableViewController.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
ref.attributedTitle = NSAttributedString(string: "????????")
tableView.addSubview(ref)
}
func updateSearchResultsForSearchController(searchController: UISearchController)
{
indicator.startAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
tableView.reloadData()
getRequests.getProduct(tableView, spinner: indicator,name: searchController.searchBar.text!)
for …Run Code Online (Sandbox Code Playgroud) 我有一个ios应用程序,我使用apns发送推送.我需要处理推送消息,如果正确则显示消息.我怎样才能迅速实现它?这是我的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[NSObject: AnyObject]?) -> Bool {
registerForPushNotifications(application)
return true
}
func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""
for i in 0..<deviceToken.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
print("Device Token:", tokenString)
}
func application(application: UIApplication, …Run Code Online (Sandbox Code Playgroud) 我需要创建音频播放器。我从 url 获取音频,然后从 url 下载音频,然后播放。但是我需要在音频下载时播放音频我该怎么做?
这是我的代码如何从 url 播放它:
func URLSession(session: NSURLSession,
downloadTask: NSURLSessionDownloadTask,
didFinishDownloadingToURL location: NSURL){
do {
loadingView.hidden=true
actInd.stopAnimating()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
player=try AVAudioPlayer(contentsOfURL: location)
player?.delegate=self
selectedAudio.status=true
selectedAudio.isDownload=true
player?.enableRate=true
switch speedType_Index {
case 0:
appDelegate.player?.rate=Float(1)
break
case 1:
appDelegate.player?.rate=Float(1.5)
break
case 2:
appDelegate.player?.rate=Float(2)
break
case 3:
appDelegate.player?.rate=Float(0.5)
break
default:
break
}
switch playingType_Index {
case 0:
appDelegate.player?.numberOfLoops = 0
break
case 1:
appDelegate.player?.numberOfLoops = -1
break
default:
break
}
player?.volume=Float(volume)
player?.play()
self.tableView.reloadData()
}catch let error as NSError{
print(error.localizedDescription)
} …Run Code Online (Sandbox Code Playgroud)