Sponsored

iOS Table View টিউটোরিয়াল

0
1

প্রায় অ্যাপে টেবিল ভিউ ব্যবহৃত হয়। আমরা দেখব কিভাবে টেবিল ভিউ ব্যবহার করা যায়। একটা প্রজেক্ট তৈরি করে নিব প্রথমে। এরপর Object Library থেকে TableView মেইন স্টোরিবোর্ডে যুক্ত করি।  Table View টি সিলেক্ট করে Attributes Inspactor থেকে Prototype Cell ভ্যালু সেট করে দিব 1. নিচের ছবিটি দেখিঃ

prototype cell

 

Document Outline শো করি। Cell সিলেক্ট করে Attributes Inspector থেকে Identifier থেকে একটা ভ্যালু সেট করি। এ ভ্যালুটা আমাদের দরকার হবে। এখানে আমি দিয়েছি Cell.

Cell identifier

Assistant Editor এ ক্লিক করে আমাদের টেবিল ভিউ ViewControlar.swift এর সাথে outline হিসেবে যুক্ত করি। যে কোন একটা নাম দিতে পারি। এ উদাহরণে দিলাম tableView.

আমরা এই অ্যাপে টেবিলে বাংলাদেশের প্রধান শহর গুলোর লিস্ট দেখাবো। বাংলাদেশের প্রধান শহর গুলোর একটা অ্যারে তৈরি করে নি।

 

টেবিল ভিউ ব্যবহার করার জন্য আমাদের দুইটা মেথড অবশ্যই ইম্পপ্লিমেন্ট করতে হবে। সে গুলো হচ্ছেঃ

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

    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        
   
    }

আমাদের সম্পূর্ণ ViewControllar.swift:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet var tableView: UITableView!
    
    var cities = ["Dhaka", "Chittagong", "Sylhet", "Rajshahi", "Khulna", "Barisal", "Rangpur"]
    
    

    override func viewDidLoad() {
       
        super.viewDidLoad()
      
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
      
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        
        return cities.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
        
        cell.textLabel?.text = cities[indexPath.row]
        
        return cell
    }
    
    
 
    

}




এখন যদি আমরা অ্যাপটি রান করি, তাহলে আমরা সুন্দর একটা টেবিল দেখতে পাবো।

টেবিলের প্রতিটা আইটেমে আমরা ক্লিক করলে কি কাজ করবে, তা আমরা সেট করে দিতে পারি। তার জন্য আরেকটা মেথড ইমপ্লিমেন্ট করতে হবে। তা হচ্ছে didSelectRowAtIndexPath। এই ডেমো অ্যাপের জন্য যে কোন রোতে ক্লিক করলে তা কনসোলে প্রিন্ট করবে। সম্পুর্ণ ViewControllar.swift:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet var tableView: UITableView!
    
    var cities = ["Dhaka", "Chittagong", "Sylhet", "Rajshahi", "Khulna", "Barisal", "Rangpur"]
    
    

    override func viewDidLoad() {
       
        super.viewDidLoad()
      
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
      
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        
        return cities.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
        
        cell.textLabel?.text = cities[indexPath.row]
        
        return cell
    }
    
    
    // Check if selected
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        
        let row = indexPath.row
        print(cities[row])
    }
    

}




Search
Categories
Read More
Hacking Course
PROXY Download Api ওয়েবসাইট এখন নিজেই তৈরি করুন! [Github + Vercel Deployed]
WELLCOME BACK 𝑯𝒆𝒍𝒍𝑜 𝒈𝒖𝒚𝒔, 𝒉𝑜𝒘 𝑎𝑟𝑒 𝑦𝑜𝑢? 𝐻𝑜𝑝𝑒 𝑦𝑜𝑢 𝑎𝑟𝑒 𝑑𝑜𝑖𝑛𝑔 𝑤𝑒𝑙𝑙! 𝑆𝑜 𝑙𝑖𝑘𝑒 𝑒𝑣𝑒𝑟𝑦 𝑑𝑎𝑦, 𝑡𝑜𝑑𝑎𝑦 𝐼𝑎𝑚...
By Nettumi 2026-09-25 16:57:51 0 19
Nulled
Newsprk v1.1 - Vue JS Newspaper Template Free Download
Newsprk v1.1 – Vue JS Newspaper Template Free Download. Newsprk is an Attractive and...
By Nettumi 2026-09-18 03:54:01 0 105
Hacking Course
🖥️📐 Microsoft Word-এ Footer সেট করার সম্পূর্ণ নিয়ম – Step-by-Step Professional Guide 📝💥
আসসালামু আলাইকুম সবাই কেমন আছেন…..? আশা করি সবাই আছেন । আমি আল্লাহর রহমতে ভালোই আছি ।আসলে...
By Nettumi 2026-09-25 16:51:58 0 10
Hacking Course
এবার মহাকাশ থেকে আসছে বিদ্যুৎ
বর্তমান সময়ে নবায়নযোগ্য শক্তির উৎসের ব্যবহারের মধ্যে সবচেয়ে দ্রুততম বর্ধিত রূপ হচ্ছে সৌরশক্তি।...
By Nettumi 2026-09-25 09:47:41 0 19
Nulled
AWK Screen Recorder with Audio (Android 10 supported) App Source
AWK Screen Recorder with Audio (Android 10 supported) App Source Code Free Download. AWK...
By Nettumi 2026-09-18 03:59:37 0 24
‎ ‎ ‎
Nettumi https://nettumi.com