Home>
I am creating an iOS app using the swift language with xCode.
Do not place anything on StoryBoard, just create a ViewController,
I want to implement the contents only with code.
We received a response from takabosoft, the code was corrected, and the error was resolved.
However, I am trying to set it, but neither text nor images are displayed.
Thanks for your cooperation.
・ Image of each cell I want to create
---------------
Name: 〇〇 | Display image
---------------
Nothing is displayed.
Applicable source codeimport UIKit
class CustomTableViewCell: UITableViewCell {
var id = UILabel ()
var icon = UIImageView ()
override func awakeFromNib () {
super.awakeFromNib ()
// Initialization code
}
override func setSelected (_ selected: Bool, animated: Bool) {
super.setSelected (selected, animated: animated)
// Configure the view for the selected state
}
func setCell (idList: IDList) {
self.id.text = idList.id
self.icon.image = UIImage (named: idList.imgName)
}
}
import Foundation
// Model for ID selection screen
class IDList: NSObject {
var id: String!
var imgName: String!
init (sId: String, imgName: String!) {
self.id = sId
self.imgName = imgName
}
}
* Excerpt
var testData: [IDList] = [IDList] ()
override func viewDidLoad () {
super.viewDidLoad ()
// Get the screen size
let iWidthScreen = self.view.frame.size.width
let iHeightScreen = self.view.frame.size.height
// title
let lblTitle = UILabel ()
lblTitle.frame = CGRect (x: 0, y: 45, width: iWidthScreen, height: 20)
lblTitle.text = "Title"
lblTitle.textAlignment = NSTextAlignment.center
self.view.addSubview (lblTitle)
// ID list
let tableView = UITableView ()
tableView.frame = CGRect (x: 5, y: iHeightScreen * 0.15, width: iWidthScreen-10, height: iHeightScreen * 0.7)
tableView.delegate = self
tableView.dataSource = self
self.view.addSubview (tableView)
// Done button
let btnConplete = UIButton ()
btnConplete.frame = CGRect (x: iWidthScreen * 0.1, y: iHeightScreen * 0.9, width: iWidthScreen * 0.8, height: 50)
btnConplete.setTitle ("Button 1")
btnConplete.layer.cornerRadius = 12
btnConplete.addTarget (self, action: #selector (btnNext_touched), for: .touchUpInside)
self.view.addSubview (btnConplete)
}
// TableView display quantity
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int)->Int {
return testData.count
}
// Set value in cell
Func tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath)->UITableViewCell {
let cell: CustomTableViewCell = tableView.dequeueReusableCell (withIdentifier: "CustomTableViewCell", for: indexPath) as! CustomTableViewCell
cell.id.frame = CGRect (x: 0, y: 0, width: 150, height: 30)
cell.id.text = testData [indexPath.row] .id
cell.imgName.image = UIImage (named: testData [indexPath.row] .imgName
return cell
}
Supplemental information (FW/tool version etc.)
・ Mac
・ XCode 10.1
・ Swift 3
-
Answer # 1
Related articles
- ios - i want to implement processing by combining long press and drag in swift
- [swift] how to implement context menu in tableview of macos
- js to implement a custom right-click menu
- ios - [swiftui] i want to apply a custom modifier to a shape such as rectangle, but i get an error [custom modifier]
- C ++ uses a template class to implement a chained stack
- xcode - i cannot run a custom class that displays a datepicker when i tap the textfield
- ios - custom cell is only displayed on one device
- ios - how to resolve favtableview error "this class is not key value coding-compliant for the key favtableview"
- ios - i want to display the value displayed in each cell of swift and tableview in another view about conditional branch using t
- ios - tapping a button in a custom cell changes the button title
- Detailed java custom class
- ios - [swift] reason 2 "project name class name"
- Python3 sorted how to implement custom sorting criteria
- Sample code for vuejs custom component to implement v-model two-way data binding
- Android custom ListView to implement the QQ space interface
- js implement mouse click page pop-up custom text effect
- Android custom TimeButton to implement countdown button
- Sample code for Flutter to implement various custom shapes with Clipper
- Android custom components to implement meter count dial
- ios - i want to implement an animation that fades in
Related questions
- ios - [xcode] regarding the screen transition, it became a strange screen display
- ios - i can't see the keyboard in the xcode simulator
- [ios] effect of setting enable bitcode to false
- ios - data of authauth () currentuser? uid cannot be deleted even if the application is deleted
- ios - i want to change the title from the keyboard when i tap annotation in swift
- ios - i want to pass an array containing tuples in swift and userdefaults
- ios - i want to display the initial text value of uitextfield in swiftui
- ios - i want to set the title on the screen with tabbar under navigationcontroller in swift5
- ios - i don't see the xcode simulator
- ios - i want to convert string to date type in swift4
It's a UITableViewCell custom class, not UITableView.
In the middle of ViewController's viewDidLoad
If you executeetc., a custom class for the cell will be generated.