mitter.io
  • Welcome
  • Migrating from cloud to on-prem
  • Get mitter.io
    • Custom configuration
  • Getting started
    • Build Your First Android App
      • Setup
      • Authenticate a User
      • Start a Basic Chat
      • Selective Deliveries
      • Custom Payloads
    • Build Your First iOS App
      • Overview
      • Installation
      • Basic Setup
      • Receive Push Messages
      • Storyboard
      • Channel List
      • Channel Window
    • Build Your First Web App
      • Setting Up Your App
      • Start a Basic Chat
      • Selective Deliveries
    • Build Your First React Native app
  • Platform Reference
    • Introduction
    • Concepts
    • Authorization and Access
    • Calling the APIs
    • Users
    • Channels
      • Channel Streams and Typing Indicators
    • Messages
    • Delivery Endpoints (Push Notifications)
    • Federated Authentication
    • Basic Permissions and Privileges
    • ACLs and Advanced Permission Model
    • Metadata
  • SDKs
    • Android
      • Getting Started
      • Set up FCM
      • Presence and Timeline Events
      • Profiles, Pagination and Locators
      • Using the UI Framework
    • iOS
      • Installation
      • Basic Setup
      • Get the current user details
      • Create a Channel
      • Messaging
      • Push Messages
    • Javascript
      • Using the UI framework (web only)
      • For react-native
      • For node.js
      • TSDocs / JSDocs
      • For Typescript Users
    • Java (Backend)
Powered by GitBook
On this page
  1. Getting started
  2. Build Your First iOS App

Channel List

The ChannelListViewController contains a simple TableView that shows a list of Channels. This section will only deal with the essential functionality and not styling.

Set up the TableView like so in your viewDidLoad:


// This is the data backing the TableView
var channels = [ParticipatedChannel]()

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Get the AppDelegate which contains the Mitter object
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    
    // TableView setup
    ...
    
    // Fetch the list of channels and display
    appDelegate.mitter.channels.getChannelsForCurrentUser {
        result in
        switch result {
        case .success(let fetchedChannels):
            self.channels = fetchedChannels
            print("Received all channels for logged in user")
            self.tableView.reloadData()

        case .error:
            print("Couldn't fetch all channels for logged in user")
        }
    }
}

To render the cell, modify the UITableViewDelegate function as follows:

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

        // create a new cell if needed or reuse an old one
        let cell: UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell!

        // set the text from the data model
        cell.textLabel?.text = self.channels[indexPath.row].channel.channelId

        return cell
    }

To open the ChannelWindowViewController on clicking a cell:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let channelWindowViewController = storyboard.instantiateViewController(withIdentifier: "channelWindowView") as! ChannelWindowViewController
        channelWindowViewController.channelId = channels[indexPath.row].channel.channelId
        navigationController!.pushViewController(channelWindowViewController, animated: true)
    }

PreviousStoryboardNextChannel Window

Last updated 6 years ago