
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
How to insert new cell into UITableView using Swift?
To insert a new cell into UITableView we'll first have to create a table view cell and then add it to the table view using Cell for row at method of Table view.
We can create a cell using Storyboard or by creating a nib of class UITableViewCell.
In the View controller drag and drop a table view and connect it's outlet to the ViewController class.
Let's create a cell in the table view we just created and create it's class, call it CustomCell, and assign the class to cell.
Give it an identifier "CustomCell"
Add a label in the cell and change it to "CustomCell", so that we can identify it, and place it in center vertically and horizontally.
Add the following code to our class
func numberOfSections(in tableView: UITableView) −> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) −> Int { return 5 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) −> UITableViewCell { let cell = tblView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomCell return cell }
When we run this code this is how it will look on the device.
- Related Articles
- How to insert new row into table at a certain index using jQuery?
- How to insert new keys/values into Python dictionary?
- Swift Program to Insert a string into another string
- How to insert new documents into a MongoDB collection in your database?
- How can we insert a new row into a MySQL table?
- How to insert an element into DOM using jQuery?
- How to insert Binary data into a table using JDBC?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- How to insert a row into a ResultSet object using JDBC?
- How to insert into two tables using a single MySQL query?
- How to insert DATE into a MySQL column value using Java?
- How to insert/store JSON array into a database using JDBC?
- How to insert a DATALINK object into a table using JDBC?
- How to insert a document into a MongoDB collection using Java?
- How to insert multiple document into a MongoDB collection using Java?

Advertisements