Loading...

Answers

Menu

Creating a TableView Programmatically with multiple cell in swift

As I am creating a TableView programmatically with multiple cell and in each cell having UICollectionView, UITableView, UITableView.... but I am not able to find the error and every time when I run the program it Shows " Command failed due to signal: Segmentation fault: 11". Has any one created this type of UI using coding. New in Swift so forgive for errors. // ViewController.swift // Json Parsing in Swift import UIKit import Alamofire import SwiftyJSON class ViewController: UITableViewController { var dataArray = Array<JSON>() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. Alamofire.request(.GET, "http://104.131.162.14:3033/api/ios/detail").validate().responseJSON { response in switch…

Answers

Thakor Dhavalsinh vishnusinh, Copy writing articles writing blogpost writing answered:

class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let tableView = UITableView()

override func viewDidLoad() {
super.viewDidLoad()

// Set the table view's frame
tableView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)

// Set the data source and delegate
tableView.dataSource = self
tableView.delegate = self

// Register the custom cell class
tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: "CustomCell")

// Add the table view as a subview
view.addSubview(tableView)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell
cell.textLabel?.text = "Row \(indexPath.row)"
return cell
}
}

the startups.com platform

Copyright © 2025 Startups.com. All rights reserved.