मेरे पास एक टेबल व्यू सेल है और 4 बटन हैं लेकिन कुछ मामलों में मैं एक अयस्क और बटन छुपा रहा हूं और टेबल व्यू सेल का आकार स्वचालित कैसे बना सकता हूं ???
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionCell")!
variant1 = cell.contentView.viewWithTag(1) as! UIButton
variant2 = cell.contentView.viewWithTag(2) as! UIButton
variant3 = cell.contentView.viewWithTag(3) as! UIButton
variant4 = cell.contentView.viewWithTag(4) as! UIButton
let questionTextView = cell.contentView.viewWithTag(5) as! UITextView
questionTextView.text = "\(Questions[indexPath.row].content!), подсказка: \(Questions[indexPath.row].hint!)"
variant1.addTarget(self, action: #selector(self.variant1ButtonPressed), for: .touchUpInside)
variant2.addTarget(self, action: #selector(self.variant2ButtonPressed), for: .touchUpInside)
variant3.addTarget(self, action: #selector(self.variant3ButtonPressed), for: .touchUpInside)
variant4.addTarget(self, action: #selector(self.variant4ButtonPressed), for: .touchUpInside)
//cell.contentView.backgroundColor = UIColor(red: 255/255, green: 0/255, blue: 0/255, alpha: 0.65)
let numberOfVars = numberOfVariants[indexPath.row]
if (numberOfVars == 2) {
variant1.setTitle(Variants[0+amaunty[indexPath.row]].title, for: .normal)
variant2.setTitle(Variants[1+amaunty[indexPath.row]].title, for: .normal)
variant3.isHidden = true
variant4.isHidden = true
}
else if (numberOfVars == 3){
variant1.setTitle(Variants[0+amaunty[indexPath.row]].title, for: .normal)
variant2.setTitle(Variants[1+amaunty[indexPath.row]].title, for: .normal)
variant3.setTitle(Variants[2+amaunty[indexPath.row]].title, for: .normal)
variant4.isHidden = true
}
else if (numberOfVars == 4) {
variant1.setTitle(Variants[0+amaunty[indexPath.row]].title, for: .normal)
variant2.setTitle(Variants[1+amaunty[indexPath.row]].title, for: .normal)
variant3.setTitle(Variants[2+amaunty[indexPath.row]].title, for: .normal)
variant4.setTitle(Variants[3+amaunty[indexPath.row]].title, for: .normal)
}
return cell
}
0
Азамат Булегенов
13 जुलाई 2017, 14:23
1 उत्तर
इस तरह के बटनों का उपयोग करने से जटिलता बढ़ेगी। प्रबंधन करने की बहुत अधिक संभावनाएं हैं।
विकल्प 1: बटन को एक अलग सेल बनाएं। प्रत्येक प्रश्न तालिका दृश्य में एक खंड होगा
विकल्प 2: बटन के बजाय UITableView का उपयोग करें। TableView की ऊंचाई गतिशील होगी और आपको विभिन्न स्थितियों के लिए प्रबंधन करने की आवश्यकता नहीं होगी।
0
rv7284
13 जुलाई 2017, 14:42
संबंधित सवाल
नए सवाल
ios
iOS, Apple iPhone, iPod टच और iPad पर चलने वाला मोबाइल ऑपरेटिंग सिस्टम है। IOS प्लेटफॉर्म पर प्रोग्रामिंग से संबंधित प्रश्नों के लिए इस टैग [ios] का उपयोग करें। उन प्रोग्रामिंग भाषाओं के लिए विशिष्ट मुद्दों के लिए संबंधित टैग [उद्देश्य-सी] और [स्विफ्ट] का उपयोग करें।