Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Code 碎片整理 #47

Open
v5tech opened this issue Jan 16, 2015 · 0 comments
Open

Swift Code 碎片整理 #47

v5tech opened this issue Jan 16, 2015 · 0 comments

Comments

@v5tech
Copy link
Owner

v5tech commented Jan 16, 2015

Swift Code 碎片整理

1. NSURLConnection

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

2. UIAlertView

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)

3. navigationItem

//设置导航栏按钮(左边)
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant