Skip to main content

Around2Me – Instantly Discover Nearby Essentials

In today’s fast-paced world, finding what you need — exactly when you need it — should be effortless. That’s where Around2Me comes in. Whether you're navigating a new city, running errands, or just looking for a bite nearby, Around2Me helps you instantly find nearby essentials like ATMs, restaurants, hospitals, gas stations , and much more. Around2Me 🚀 What Makes Around2Me Different? Unlike many location-based apps that are bloated with unnecessary features or force users to sign up, Around2Me is lightweight, private, and instant . Here's how: 📍 Location-Based Discovery The app instantly detects your current location and shows you relevant nearby places — from pharmacies to petrol pumps, cafes to banks. 🗺️ Map Integration Tap any place to view it on the map and get turn-by-turn directions in seconds. 🧩 Clean Categories Looking for something specific? Use quick-access filters like Hospitals , ATMs , Coffee Shops , or Parking . 🔐 No Signups, No Data Collection ...

How to Use Multiple Sections in UITableView iOS Swift !

Multiple sections in UITableView iOS Swift.

UITableView is very important part of iOS ecosystem. So we split tableviews in sections. Then its easier to find right information. 


Multiple Sections in UITableView iOS Swift 5


1. First let’s create a project as usual. Create a new single view application X code project. Set project name to UIViewController. 

2. Go to main storyboard & select view controller & use UITableView

3. Select tableview & make it initial view controller 

4 Create a custom Sections Class like Name => TableSections, create register cell static return getCellNibsmethod. Then create  4 section enum “TableItems” then after append all sections to an array model.


import UIKit

struct CellNib{

    static func getCellNibs() -> [String] {

        return ["Cell1","Cell2","Cell3","Cell4"]

    }

}

enum TableItems: Int {

    case TableSections1

    case TableSections2

    case TableSections3

    case TableSections4

}

class TableSections: NSObject {

    var sectionType : TableItems?

    init(tItems:TableItems) {

        sectionType = tItems

    }

class func sectionsForTable()->[TableSections] {

        var sections = [TableSections]()

        sections.append(TableSections(tItems: TableItems.TableSections1))

        sections.append(TableSections(tItems: TableItems.TableSections2))

        sections.append(TableSections(tItems: TableItems.TableSections3))

        sections.append(TableSections(tItems: TableItems.TableSections4))

        return sections

}

}

5. After Create a custom 4 UITableViewCell with xib. Cell1, Cell2, Cell3, Cell4.


import UIKit

class Cell1: UITableViewCell {

    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

    } 

}

Same Cell2, Cell3, Cell4

6. After Create a TableCommonVC UIViewController and UITableViewDelegate, UITableViewDataSource, setup section, and register table cells.


import UIKit

class TableCommonVC: UIViewController, UITableViewDelegate, UITableViewDataSource{

    var tSections: [TableSections]?

    @IBOutlet weak var tlbView : UITableView!

    override func viewDidLoad() {

        super.viewDidLoad()

        self.setupSection()

        self.setTlbNibs()

        self.tlbView.reloadData()

    }

    func setTlbNibs(){

        for item in CellNib.getCellNibs() {

            let nib = UINib(nibName: item , bundle: nil)

            self.tlbView.register(nib, forCellReuseIdentifier: item)

        }

    }

    func setupSection(){

        self.tSections = TableSections.sectionsForTable()

    }

    //MARK: UITableView Delegate & DataSource

    func numberOfSections(in tableView: UITableView) -> Int {

        return (self.tSections != nil) ? self.tSections!.count:0

    }

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

        return setRows(tItems: self.tSections![section].sectionType!)

    }

    func setRows(tItems: TableItems)->Int {

        switch tItems {

            case .TableSections1:return getS1RowCount()

            case .TableSections2:return getS2RowCount()

            case .TableSections3:return getS3RowCount()

            case .TableSections4:return getS4RowCount()

        }

    }

    func getS1RowCount()->Int{ return 0 }

    func getS2RowCount()->Int{ return 0 }

    func getS3RowCount()->Int{ return 0 }

    func getS4RowCount()->Int{ return 0 }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        return setCells(indexPath: indexPath)!

    }

    func setCells(indexPath: IndexPath)-> UITableViewCell? {

        let tItem = tSections![indexPath.section]

        switch tItem.sectionType! {

        case .TableSections1:return getCellS1(indexPath: indexPath)

        case .TableSections2:return getCellS2(indexPath: indexPath)

        case .TableSections3:return getCellS3(indexPath: indexPath)

        case .TableSections4:return getCellS4(indexPath: indexPath)

        }

    }

    func getCellS1(indexPath:IndexPath)->UITableViewCell?{ return nil }

    func getCellS2(indexPath:IndexPath)->UITableViewCell?{ return nil }

    func getCellS3(indexPath:IndexPath)->UITableViewCell?{ return nil }

    func getCellS4(indexPath:IndexPath)->UITableViewCell?{ return nil }

}


7. Now Create a TableSectionDemoVC for visibility tableview and override UITableView numberOfRowsInSection and  cellForRowAt methods.

import UIKit

class TableSectionDemoVC: TableCommonVC{

    override func viewDidLoad() {

        super.viewDidLoad()

        self.setTlbNibs()

        self.tlbView.reloadData()

    }

    override func getS1RowCount()->Int{ return 1 }

    override func getS2RowCount()->Int{ return 1 }

    override func getS3RowCount()->Int{ return 1 }

    override func getS4RowCount()->Int{ return 1 }

    

    override func getCellS1(indexPath:IndexPath)->UITableViewCell?{

        if let hCell = self.tlbView.dequeueReusableCell(withIdentifier: "Cell1") as? Cell1{

            hCell.selectionStyle = .none

            return hCell

        }

        return nil

    }

    override func getCellS2(indexPath:IndexPath)->UITableViewCell?{

        if let hCell = self.tlbView.dequeueReusableCell(withIdentifier: "Cell2") as? Cell2{

            hCell.selectionStyle = .none

            return hCell

        }

        return nil

    }

    override func getCellS3(indexPath:IndexPath)->UITableViewCell?{

        if let hCell = self.tlbView.dequeueReusableCell(withIdentifier: "Cell3") as? Cell3{

            hCell.selectionStyle = .none

            return hCell

        }

        return nil

    }

    override func getCellS4(indexPath:IndexPath)->UITableViewCell?{

        if let hCell = self.tlbView.dequeueReusableCell(withIdentifier: "Cell4") as? Cell4{

            hCell.selectionStyle = .none

            return hCell

        }

        return nil

    }

}

 

Overview

Table views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app’s content.
For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings.
You can configure a table to display a single long list of rows, or you can group related rows into sections to make navigating the content easier. :- https://developer.apple.com/documentation/uikit/uitableview

How to Create UITableView with multiple sections in iOS ,Binding a list with multiple sections and different cells,Build Sections With Nested Types UITableView,UITableView with multiple sections swift 5 ,Dynamic sections UITableView example swift 5,UITableView swift uitableview style grouped programmatically swift ,Set section in uitableview swift


Comments

Post a Comment