# 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.

&#x20;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)
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mitter.io/getting-started/build-your-first-ios-app/channel-list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
