Introduction
In this article, we will learn how to create an iOS application using Xamarin. We will learn how to add and work with a table view and its row swipe action. We will have a table of contents and we will swipe the row to the left to perform an action.
Prerequisite
- Basic knowledge of C# and programming.
- Knowledge of Xamarin.
This article will cover the following.
- Xamarin iOS application.
- Table View in the application.
- TableViewDelegate for performing TableViewAction.
Implementation
Open Visual Studio Community Edition.
Select the single view app and click "Next".

Give the app a name and click "Next".
Give project and solution names and create the application.
Open Main.storyboard and add the Table View to your controller.
Open toolbox pad and search for tableview and drag the View to your controller.
Resize it and set the name property to “CarsTable”.
Add two class files to your solution.
- CarSource.cs
- using System;
- using System.Collections.Generic;
- using Foundation;
- using UIKit;
- namespace SwipeTable {
- public class CarSource : UITableViewSource {
- List<String> cars;
- public CarSource(List<String> source) {
- this.cars = source;
- }
- public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) {
- var cell = new UITableViewCell(UITableViewCellStyle.Default, "");
- cell.TextLabel.Text = cars[indexPath.Row];
- return cell;
- }
- public override nint RowsInSection(UITableView tableview, nint section) {
- return cars.Count;
- }
- }
- }
- CarDelegate.cs
- using System;
- using UIKit;
- namespace SwipeTable {
- public class CarsDelegate : UITableViewDelegate {
- public override UITableViewRowAction[] EditActionsForRow(UITableView tableView, Foundation.NSIndexPath indexer) {
- var action = UITableViewRowAction.Create(
- UITableViewRowActionStyle.Default, "Like", (arg1, arg2) => {
- var cell = tableView.CellAt(arg2);
- cell.TextLabel.Text += " ( Liked )";
- }
- );
- return new UITableViewRowAction[] { action };
- }
- }
- }


Naresh SinghalPosted Jan 22, 2018, 11:36 PM
Very good explained Mohammad.......