ios - Programmatically change the image of a button in a table cell -


// objectsAry है NSManagedObjects

  // मुख्य दृश्य नियंत्रक वर nowImg = UIImage ( नामांकित: "img30.png") फ़ंक तालिका दृश्य (तालिका दृश्य: UITableView, सेलफोररौअटइंडएपपाठ सूचकांक: NSIndexPath) - & gt; UITableViewCell {var NuTblCellInst = NuTableViewCell () var मुख्यसेल: UITableViewCell = self.mainList.dequeueReusableCellWithIdentifier ("मुख्यसेल") के रूप में NuTableViewCell maincell.textLabel.text = self.objectsAry [indexPath.row] .valueForKey ("itemname") के रूप में? स्ट्रिंग //NuTblCellInst.doImgLoad(nowImg) // टिप्पणी हटाएं ऊपर = गंभीर त्रुटि लाइन: अप्रत्याशित रूप से पाया नहीं के बराबर है जबकि एक वैकल्पिक मूल्य unwrapping // यह अगर मैं विधि का उपयोग कोई फर्क नहीं पड़ता या सीधे NuTblCellInst.btnWImg.setBackgroungImage का उपयोग करें (unwrapping त्रुटि या तो किसी भी तरह से) वापसी मुख्यसेल} // कस्टम टेबलव्यू सेल कक्षा वर्ग NuTableViewCell: UITableViewCell {@Iboutlet कमजोर var btnWImg: UIButton! Var nowImg = UIImage (नामित: "img30.png") func doImgLoad (theImg: UIImage) {btnWImg.setBackgroundImage (theImg, forState: UIControlState.Normal)} ओपरराइड फ़्ंनकफ़्रेम्मेलफ़ोमनीब () {super.awakeFromNib () // doImgLoad (अब इमग !) // टिप्पणी हटाएं ऊपर है और यह कोई समस्या नहीं बटन को छवि लोड} ओवरराइड लाइन setSelected (समारोह चयनित: बूल, एनिमेटेड: बूल) {super.setSelected (चयनित, एनिमेटेड: एनिमेटेड)}}  

मैं एक पुन: प्रयोज्य सेल w / text को ऊपर बताएगा, लेकिन यह सुनिश्चित नहीं है कि स्टोरीबोर्ड का उपयोग करते हुए तालिका सेल में रखा गया बटन के लिए छवि (या पृष्ठभूमि छवि) तक पहुंच कैसे करेगी जहां छवि तालिका पंक्ति के साथ भिन्न होगी ।

से '... तालिका पंक्ति के साथ भिन्न हो जाएगा,' ऐसा लगता है कि आप निर्माण कर रहे हैं एक पुन: प्रयोज्य टेम्पलेट सेल।

  1. CustTableViewCell से प्राप्त किया जाना चाहिए UITableViewCell
  2. में अपने टेम्पलेट सेल का संपादन स्टोरीबोर्ड संपादक ...
    • पहचान निरीक्षक में, अपने कस्टम वर्ग
    • CustTableViewCell
    • <में बटन के लिए एक आउटलेट बनाने के लिए वर्ग सेट / ul>
    • में tableview: cellForRowAtIndexPath
      • / विपंक्ति <कोड बनाने> maincell एक <कोड के रूप में> CustTableViewCell - नहीं UITableViewCell
      • आउटलेट के माध्यम से बटन पर गुण सेट करें
      • अपने उदाहरण लौटाएं (बेशक :-))

सीएफ


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -