My company had few requests to build mobile application, but they had only me - .net guy. That’s why they chose Xamarin as framework for developing their mobile applications. Xamarin allow create iOS/Android apps in C#. And now I want to write small quick start tutorial how to create iOS app with Xamarin.
So lets start… We’ll write small news app in this tutorial, the news source will be bbc.co.uk. Here you can find REST interface to access BBC News http://api.bbcnews.appengine.co.uk/ . When I am writing this article I supposing you already have Xamarin, Xamarin Studio installed.
In Xamarin Studio, choose C# > iOS > iPhone in the left-hand pane, and then, in the center pane, select Empty Project template from the center pane. This will create a new Xamarin.iOS iPhone application.
In AppDelegate on FinishedLaunching method write following code:
This code will add root navigation controller and push new CategoryController into navigation.
Create folder where we’ll store our View Controllers, call it “Controllers”. Let’s create CategoryController first. The code of this controller is quite simple: on ViewDidLoad we add new UITableView (simple table), setup dimensions, and fill in with data calling specific API url. Look code below:
As you can see when we filling table with data we are using CategoryTableSource class. This is class delivered from standard UITableViewSource class. Cerate AL folder (Application Layer), we’ll use this folder to extend some default controls etc. Create CategoryTableSource class and put code:
As you see all we do in this class is:
This was a quick start with Xamarin. If you have any questions please ask in comments and I'll try answer on all of them :) Also visit official Xamarin website. There are a lot tutorials, documentation and receipts on it.
Here is promised url to sources: https://github.com/ybigus/xamarin-news-demo
P.S. As home task try to make API calls async. It's really simple stuff with c#.
So lets start… We’ll write small news app in this tutorial, the news source will be bbc.co.uk. Here you can find REST interface to access BBC News http://api.bbcnews.appengine.co.uk/ . When I am writing this article I supposing you already have Xamarin, Xamarin Studio installed.
In Xamarin Studio, choose C# > iOS > iPhone in the left-hand pane, and then, in the center pane, select Empty Project template from the center pane. This will create a new Xamarin.iOS iPhone application.
In AppDelegate on FinishedLaunching method write following code:
This code will add root navigation controller and push new CategoryController into navigation.
Create folder where we’ll store our View Controllers, call it “Controllers”. Let’s create CategoryController first. The code of this controller is quite simple: on ViewDidLoad we add new UITableView (simple table), setup dimensions, and fill in with data calling specific API url. Look code below:
As you can see when we filling table with data we are using CategoryTableSource class. This is class delivered from standard UITableViewSource class. Cerate AL folder (Application Layer), we’ll use this folder to extend some default controls etc. Create CategoryTableSource class and put code:
As you see all we do in this class is:
- Fill in categories table
- Override RowsInSection method (and return total amount of categories)
- Override UITableViewCell for customization of our cells. Please note you can create your own custom table cell by inheritance from UITableViewCell class. We’ll not use this in our example, because standard layout is enough for us, we just saying which fields of our Category show and where.
- Override RowSelected method for catch clicks on specific rows. Now create NewsController class which will show news by choosed category. Try to do this yourself but I am attaching full source url ofcource, so you can take a look or try application. If you will run it you’ll see following screens.
Here is promised url to sources: https://github.com/ybigus/xamarin-news-demo
P.S. As home task try to make API calls async. It's really simple stuff with c#.
The case also goes if you don’t want to learn a specific language to iXamarin framework for iOS or Android. One can take advantage of powerful C# features such as LINQ, unidentified types etc. It provides full access to all the innate APIs which makes it possible for a developer to develop native apps with device-specific skills.
ReplyDeleteGood job on Xamarin
ReplyDeleteXamarin technology is ruling the App development industry now!
DevRabbit is helping the start ups and large businesses in accelerating their growth through cutting edge technology by leveraging Mobile App Development for iPhone and Android, Cloud Solution, Web Application Development & Big data analytics solutions, Digital Marketing services. DevRabbit is a Xamarin Consulting Company.