Buka halaman Web yang berbeda dengan tombol pada ViewController tunggal

Saya tahu cara mengimplementasikan tampilan web di aplikasi saya dan sekarang saya hanya ingin menggunakan satu ViewController untuk membuka halaman web berbeda di situs saya, seperti ini:

Pengontrol tampilan pertama memiliki tombol: tombol1, tombol2 dan tombol3.

Kemudian di viewcontroller kedua:

  • jika tombol 1 diklik: mysite.com
  • jika tombol2 diklik: mysite.com/page
  • jika tombol3 diklik: mySite.com/Page2

Sejauh ini saya telah membuat satu viewcontroler per kategori, jadi saya punya banyak kategori dan ini lebih membuat frustrasi.

Saya ingin menjumlahkan seperti ini: masukkan deskripsi gambar di sini


person Ninder Chand    schedule 07.10.2016    source sumber
comment
Bisakah Anda menambahkan beberapa kode dan cuplikan layar?   -  person nishith Singh    schedule 07.10.2016


Jawaban (1)


masukkan deskripsi gambar di siniYa, Anda dapat membuka beberapa tautan dalam tampilan web yang sama dengan mengeklik tombol berbeda seperti

 myWebView = UIWebView(frame: CGRectMake(0,0,   self.view.frame.size.width,self.view.frame.size.height-100))

        myWebView.delegate = self
        self.view.addSubview(myWebView)

    let Button1 = UIButton(frame: CGRectMake(10,self.view.frame.size.height-50,50,50))
         Button1.setTitle("Link 1", forState: .Normal)

        Button1.setTitleColor(UIColor.redColor(), forState: .Normal)
        Button1.addTarget(self, action: #selector(button1Action), forControlEvents: .TouchUpInside)

         self.view.addSubview(Button1)


        let Button2 = UIButton(frame: CGRectMake(150,self.view.frame.size.height-50,50,50))
         Button2.setTitle("Link 1", forState: .Normal)
        Button2.setTitleColor(UIColor.redColor(), forState: .Normal)

        Button2.addTarget(self, action: #selector(button2Action), forControlEvents: .TouchUpInside)

        self.view.addSubview(Button2)

         let Button3 = UIButton(frame: CGRectMake(250,self.view.frame.size.height-50,50,50))
         Button3.setTitle("Link 1", forState: .Normal)
        Button3.setTitleColor(UIColor.redColor(), forState: .Normal)

        Button3.addTarget(self, action: #selector(button3Action), forControlEvents: .TouchUpInside)

        self.view.addSubview(Button3)
     }

     func button1Action()
    {
        let myUrl = NSURL(string: "https://www.google.co.in")

        let request = NSMutableURLRequest(URL: myUrl!)
       myWebView.loadRequest(request)

    }

     func button2Action()
    {

         let myUrl = NSURL(string: "http://stackoverflow.com/questions/tagged/ios")
        let request = NSMutableURLRequest(URL: myUrl!)
        myWebView.loadRequest(request)

    }

    func button3Action()
    {
        let myUrl = NSURL(string: "http://stackoverflow.com/questions/39916960/open-diffrent-webpage-with-button-on-single-viewcontroller")
        let request = NSMutableURLRequest(URL: myUrl!)
        myWebView.loadRequest(request)

    }

Dan jangan lupa atur di info.plist App Transport Security Settings menjadi Allow arbitrary load truemasukkan deskripsi gambar di sini

person mukul    schedule 07.10.2016
comment
bagaimana saya bisa memberi nama tombol saya? di segue? - person Ninder Chand; 07.10.2016
comment
Saya menggunakan Swift .. CGRectMake Tidak Tersedia di Swift - person Ninder Chand; 07.10.2016