var url = NSURL(string: "http://www.stackoverflow.com")
var request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
})
let alertView:UIAlertView = UIAlertView()
alertView.title="提示"
alertView.message="恭喜你,你中奖了!"
alertView.addButtonWithTitle("确定")
alertView.show()
或者
var alert:UIAlertController = UIAlertController(title: "提示", message: "恭喜你,你中奖了!", preferredStyle: UIAlertControllerStyle.Alert)
var action: UIAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: {
ac -> Void in
})
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
//设置导航栏按钮(左边)
let leftBarButtonItem:UIBarButtonItem = UIBarButtonItem(title: "主页", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("showMain"))
self.navigationItem.leftBarButtonItem = leftBarButtonItem
//设置导航栏按钮(右边)
let rightBarButtonItem:UIBarButtonItem = UIBarButtonItem(title: "设置", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("showSetting"))
self.navigationItem.rightBarButtonItem = rightBarButtonItem
//设置导航栏名称
self.navigationItem.title="全国主要城市PM2.5"
func showMain(){
//SCLAlertView().showTitle(self, title: "提示", subTitle: "你点击了主页", duration: 2.0, style: SCLAlertViewStyle.Info)
var alert = UIAlertController(title: "提示", message: "你点击了主页", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: {
(UIAlertAction) -> Void in
println("你点击了确定按钮")
}))
self.presentViewController(alert, animated: true, completion: nil)
}
func showSetting(){
//SCLAlertView().showTitle(self, title: "提示", subTitle: "你点击了设置", duration: 2.0, style: SCLAlertViewStyle.Info)
var alert = UIAlertController(title: "提示", message: "你点击了设置", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: {
(UIAlertAction) -> Void in
println("你点击了确定按钮")
}))
self.presentViewController(alert, animated: true, completion: nil)
}