Les boutons qui apparaissent dans la deuxième vue sont ajoutés par programmation. Comment le rendre invisible dans la vue?Les boutons apparaissent également dans la deuxième vue, même s'ils passent à différents ViewController
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var mainScrollView: UIScrollView!
@IBOutlet weak var tableview: UITableView!
var Hotel_Name = [String]()
var itemView = UIView()
var identities = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// let buttonAYŞE = Otel_1(text: "AYŞE")
// let buttonBREZKEMER = Otel_2(text: "BREZ KEMER")
//
// buttonAYŞE.alpha = 0
// buttonBREZKEMER.alpha = 0
identities = ["listTable", "scrollview"]
//****** Aşağıdaki kapalı olan JSONSerialization yapısı açıldığında web servisten çektiği verileri tableview'e aktarmaktadır. Üstteki HotelModel fonksiyonu kapatldığı taktirde.
let urlString = "http://service.ceylaner.com.tr/hotelapi/api/hotel/GetHotels?Company_id=1&Language_id=1"
let url = URL(string: urlString)
let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error != nil{
print(error!)
}
else
{
do
{
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSArray
if let jsonDic = json
{
for i in 0..<jsonDic.count
{
if let basliklar = jsonDic[i] as? NSDictionary
{
if let Hotel_NameArray = basliklar["Hotel_Name"] as? NSString
{
self.Hotel_Name.append(Hotel_NameArray as String)
}
}
}
DispatchQueue.main.async{
self.tableview?.reloadData()
}
}
}
catch
{
print(error)
}
}
}
task.resume()
view.addSubview(Otel_1(text: "AYŞE DFDFDNKFDFMKVFKVKNFVND"))
view.addSubview(Otel_2(text: "BREZ KEMER"))
}
//buttons
public func Otel_1(text:String) -> UIButton {
let btn_1 = UIButton(type: UIButtonType.system)
//Set a frame for the button. Ignored in AutoLayout/ Stack Views
btn_1.frame = CGRect(x: 10, y: 555, width: 170, height: 100)
//Set background color
btn_1.backgroundColor = UIColor.lightText
//State dependent properties title and title color
btn_1.setTitle(text, for: .normal)
btn_1.setTitleColor(UIColor.white, for: .normal)
btn_1.titleLabel?.numberOfLines = 2
btn_1.titleLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping
btn_1.titleLabel?.textAlignment = NSTextAlignment.center
btn_1.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
return btn_1
}
func Otel_2(text:String) -> UIButton {
let btn_2 = UIButton(type: UIButtonType.system)
//Set a frame for the button. Ignored in AutoLayout/ Stack Views
btn_2.frame = CGRect(x: 195, y: 555, width: 170, height: 100)
//Set background color
btn_2.backgroundColor = UIColor.lightText
//btn_1.backgroundColor = UIColor.blue
//State dependent properties title and title color
btn_2.setTitle(text, for: .normal)
btn_2.setTitleColor(UIColor.white, for: .normal)
btn_2.titleLabel?.numberOfLines = 2
btn_2.titleLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping
btn_2.titleLabel?.textAlignment = NSTextAlignment.center
btn_2.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
return btn_2
}
func buttonAction(sender: UIButton!) {
// Button action'ı ile diğer Main viewcontroller'ından setting viewcontroller'ına geçer.
// let goBoard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "InfoView")
var InfoView = self.storyboard!.instantiateViewController(withIdentifier: "InfoView") as! UIViewController
self.present(InfoView, animated: true, completion: nil)
InfoView.modalTransitionStyle = UIModalTransitionStyle.coverVertical // animasyon ekleme
}
// tableView Methodları
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Hotel_Name.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as! CustomCell
cell.InfoLabel.text = Hotel_Name[indexPath.row]
cell.InfoLabel.textColor = UIColor.white
cell.InfoImage.image = UIImage(named:"logo")
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Le bouton sur l'écran est cliqué.
L'écran 2 montrant les boutons sur le 1er écran.
J'ai créé le programme UIButton. Buttonaction est en cours. Les boutons 1 sur l'écran sont en cours de transfert vers le 2ème écran. Dois-je diviser les vues, je montre la mauvaise vue. Ou est-ce que l'action ajoute quelque chose en plus?
J'ai ajouté tout le code que j'ai écrit dans le ViewController.
afficher la mise en œuvre de 'buttonAction' s'il vous plaît – Sweeper
Comment allez-vous naviguait à l'écran suivant? – anoop4real
S'il vous plaît lire [Dans quelles circonstances puis-je ajouter "urgent" ou d'autres phrases similaires à ma question, afin d'obtenir des réponses plus rapides?] (// meta.stackoverflow.com/q/326569) - le résumé est que ce n'est pas un moyen idéal de s'adresser aux volontaires, et est probablement contre-productif pour obtenir des réponses. Merci de ne pas ajouter ceci à vos questions. – halfer