में स्विफ्ट के साथ कस्टम टेबल व्यू सेल, इसलिए, मैंने बाईं ओर वाले लेबल के साथ एक कस्टम टेबल व्यू सेल बनाया और दाईं ओर एक UIImageView बनाया। लेबल 100 और UIImageView का एक टैग है 110xcode 6
मेरे कोड का एक टैग निम्नलिखित है:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("ThemeCell") as UITableViewCell
let theme = themes[indexPath.row]
var themeName = cell.viewWithTag(100) as? UILabel
themeName?.text = theme.themeName
let themeImage = cell.viewWithTag(110) as? UIImageView
themeImage?.image = UIImage(named: "test.png")
//1
//cell.imageView?.image = UIImage(named: "test.png")
println("The loaded image: \(themeImage?.image)")
return cell;
}
है के रूप में है, THEMENAME प्रदर्शित किया जाता है, लेकिन themeImage प्रकट नहीं होता है, हालांकि से println ऐसा लगता है कि छवि लोड हो गया है। यदि मैं 1 में कोड को अनदेखा करता हूं तो छवि कस्टम सेल में दिखाई देती है लेकिन निश्चित रूप से उचित स्थान पर दिखाई नहीं देती है क्योंकि यह आईआईएम में बनाए गए UIImageView में नहीं जोड़ा गया है। कोई विचार क्या मैं गलत कर सकता हूं? टैग सभी सही हैं। धन्यवाद
मेरे पास आईबी में एक कस्टम सेल है ताकि UIImageView जोड़ने में सक्षम हो, लेकिन मैंने एक MyCustomCell क्लास नहीं बनाया है जो UITableViewCell को बढ़ाता है। मुझे नहीं लगता कि मुझे इसकी ज़रूरत है। मुझे बस UILabel और UIImageView की आवश्यकता है। –
यह देखने के लिए निम्न कोड जोड़ें कि आपका 'UIImageView' प्रदर्शित किया जा सकता है:' थीम इमेज? .backgroundColor = UIColor.greenColor() '। –
http://stackoverflow.com/questions/24170922/creating-custom-tableview-cells-in-swift/38470749#38470749 –