एक XIB फ़ाइल बनाएँ:
फ़ाइल -> नई फ़ाइल -> ios-> कोको स्पर्श वर्ग -> अगले
"भी XIB फ़ाइल बनाने"
मैं tableview
के साथ प्रदर्शन करना चाहते हैं तो मैं उपवर्ग UITableViewCell
choosed आप अपने requerment
XIB फ़ाइल के रूप में चुन सकते हैं यकीन है कि जाँच चिह्न बनाने आपकी इच्छा के रूप में desing (RestaurantTableViewCell।xib)
हम पंक्ति की ऊँचाई हड़पने के लिए तालिका प्रत्येक पंक्ति hegiht
अब स्थापित करने के लिए की जरूरत है! उन्हें त्वरित फ़ाइल को पकड़ने की जरूरत है। मुझे restaurantPhoto
और restaurantName
पर हमला किया गया है, आप सभी को हुक कर सकते हैं।
अब
नाम
निब फ़ाइल है, जो .nib विस्तार शामिल नहीं की जरूरत है का नाम जोड़ना एक UITableView।
मालिक
वस्तु निब की फ़ाइल के मालिक वस्तु के रूप में आवंटित करने के लिए।
विकल्पों
एक शब्दकोश विकल्पों युक्त जब निब फ़ाइल को खोलने का उपयोग करें।
पहले .. यदि आप पहले परिभाषित नहीं करते तो सभी दृश्य grabing इसलिए यदि आप एक दृश्य हड़पने के लिए अंदर है कि सेट frist
की जरूरत है।
Bundle.main.loadNibNamed("yourUIView", owner: self, options: nil)?.first as! yourUIView
यहाँ तालिका दृश्य नियंत्रक पूर्ण कोड
import UIKit
class RestaurantTableViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let restaurantTableviewCell = Bundle.main.loadNibNamed("RestaurantTableViewCell", owner: self, options: nil)?.first as! RestaurantTableViewCell
restaurantTableviewCell.restaurantPhoto.image = UIImage(named: "image1")
restaurantTableviewCell.restaurantName.text = "KFC Chicken"
return restaurantTableviewCell
}
// set row height
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
}
आप कर :)
नोट है, इस questin पुरातन है। कई सालों से, बस कंटेनर दृश्यों का उपयोग करें [ट्यूटोरियल] (http://stackoverflow.com/questions/23399061/objective-c-how-to-add-a-subview-that-has-its-own-uiviewcontroller/23403979 # 23403979) – Fattie