申し訳ありませんが、私はSwift 2を使用していますが、まだnewbのビットです。私は、プログラムで次のコードを使用してUITabBarとのUIWebViewを作成することができました:プログラムで生成されたuiwebviewのコンテンツをプログラムで生成されたUITabBarから変更する
class ViewController: UIViewController, UIToolbarDelegate, UITabBarDelegate {
@IBOutlet var myWebView: UIWebView!
@IBOutlet weak var tabbar: UITabBar!
// @IBOutlet weak var myWebView:UIWebView! = UIWebView(frame: CGRectMake(0, 60, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height - 112))
override func viewDidLoad() {
super.viewDidLoad()
//Add Webview
let myWebView:UIWebView = UIWebView(frame: CGRectMake(0, 60, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height - 112))
myWebView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource ("index", withExtension: "htm")!))
self.view.addSubview(myWebView)
//Add Toolbar for menu
let toolbar = UIToolbar()
toolbar.frame = CGRectMake(0, 20, self.view.frame.size.width, 46)
toolbar.sizeToFit()
// make a button
let menuButton: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "list-fat-7.png"), style:.Plain, target: self, action: "twitter")
menuButton.tag = 1
toolbar.items = [menuButton]
//set toolbar color toolbar.backgroundColor = UIColor.redColor()
self.view.addSubview(toolbar)
//Add Tab Bar
let tabBar = UITabBar()
tabBar.delegate = self
tabBar.frame = CGRectMake(0, self.view.frame.size.height - 52, self.view.frame.size.width, 52)
tabBar.sizeToFit()
// Tab Bar buttons
let sermonButton = UITabBarItem(title: "Sermons", image: UIImage(named: "video-camera-7.png"), selectedImage: UIImage(named: "video-camera-7.png"))
sermonButton.tag = 1
let bibleButton = UITabBarItem(title: "Bible", image: UIImage(named: "book-cover-7.png"), selectedImage: UIImage(named: "book-cover-7.png"))
bibleButton.tag = 2
let calendarButton = UITabBarItem(title: "Calendar", image: UIImage(named: "calendar-7.png"), selectedImage: UIImage(named: "calendar-7.png"))
calendarButton.tag = 3
let givingButton = UITabBarItem(title: "Giving", image: UIImage(named: "gift-7.png"), selectedImage: UIImage(named: "gift-7.png"))
givingButton.tag = 4
let bulletinButton = UITabBarItem(title: "Bulletin", image: UIImage(named: "newspaper-7.png"), selectedImage: UIImage(named: "newspaper-7.png"))
bulletinButton.tag = 5
tabBar.items = [sermonButton,bibleButton,calendarButton,givingButton,bulletinButton]
self.view.addSubview(tabBar)
}
私は、押された「ボタン」を識別するために、このコードを使用します。
ボタン4または5のいずれかを押すと//Mapping Tab Bar Buttons
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if item.tag == 1 {
self.myWebView.loadRequest(NSURLRequest(URL: NSURL(string:"https://www.ustream.tv/combined-embed/10786920?social=0&videos=gallery&videosCount=4&html5ui")!))
} else if item.tag == 2 {
self.myWebView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource ("index", withExtension: "htm")!))
} else if item.tag == 3 {
self.myWebView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource ("Agenda", withExtension: "html")!))
} else if item.tag == 4 {
print("ApplePay")
} else if item.tag == 5 {
print("Bulletin")
}
}
対応するメッセージを表示しますが、他のボタンを押すと「致命的なエラー:オプション値(lldb)をアンラッピングしている間に予期せぬエラーが発生しました」というエラーが返されます。私はfunc tabBarでselfを追加したり削除したりすることでこれを解決しようとしましたが、成功しませんでした。私のミスはどこに見える?どんな助けもありがとう。私の後に続く人のためになるよう