我想創建一個按鈕的IBAction,當你按下它時,應用程序會在後臺運行,同時打開特定鏈接的Safari瀏覽器(例如「www.google.it」 ) 你能幫我嗎?iOS:創建一個鏈接按鈕
24
A
回答
59
裏面你IBAction爲方法,包括行
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
3
如果您使用Interface Builder:
創建一個UITextView,而不是一個UIButton,寫的聯繫,文本TextView的和選擇鏈接複選框界面生成器。它將在運行時成爲你想要的鏈接。
0
@interface ViewController : UIViewController<NSURLConnectionDelegate>
@property (strong, nonatomic) IBOutlet UIButton *okbutton;
@property (strong, nonatomic) IBOutlet UIButton *canel;
@property (strong, nonatomic) IBOutlet UITextField *textfiled;
- (IBAction)okButtonClick:(id)sender;
- (IBAction)CanelButton:(id)sender;
- (IBAction)okButtonClick:(id)sender {
NSString *searchString = textfiled.text; // UItextField.text
NSString *finalString = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",searchString];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:finalString]];
}
2
使用迅速
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.google.com")!)
或迅速3.0
UIApplication.shared.openURL(URL(string: "http://google.com")!)
相關問題
- 1. 創建一個輸入鏈接按鈕
- 2. 創建超鏈接按鈕
- 3. 創建一個按鈕,創建按鈕
- 4. 創建一個鏈接,並點擊一個按鈕點擊
- 5. 創建一個HTML按鈕與Onlick作爲一個鏈接?
- 6. 超鏈接一個按鈕
- 7. 創建一個基於區域的超鏈接按鈕
- 8. 如何添加一個鏈接到動態創建的按鈕?
- 9. Rails 3 - 創建一個按鈕/鏈接發送電子郵件
- 10. 如何創建一個鏈接到Safari的按鈕?
- 11. VBA - 可以創建一個鏈接到代碼的按鈕?
- 12. 如何創建一個ctrl按鈕超鏈接
- 13. 如何創建一個自定義按鈕鏈接到網址
- 14. 創建html按鈕鏈接 - 不工作
- 15. MFC:在按鈕中創建超鏈接
- 16. 創建一個按鈕
- 17. 在ExtJS中創建鏈接按鈕和圖像按鈕?
- 18. 創建一個熱鏈接
- 19. 如何通過一個按鈕/鏈接創建帶有下一個和後退按鈕的燈箱?
- 20. 創建一個按鈕,在jsp中單擊時創建另一個按鈕
- 21. 動態創建不同值的多個鏈接按鈕
- 22. 如何創建多個提交鏈接按鈕?
- 23. 如何創建一個隨機鏈接到多個網站的按鈕?
- 24. 加入兩個PHP變量來創建一個按鈕點擊鏈接
- 25. 如何一個接一個地動態創建按鈕?
- 26. C# - 當點擊另一個按鈕時創建一個按鈕
- 27. iOS xcode按鈕沒有鏈接。
- 28. 鏈接按鈕到另一個viewcontroll(uiwebview)
- 29. jQuery鏈接到一個按鈕
- 30. 鏈接按鈕鏈接