Posts Tagged ‘numberOfRowsInSection’

iPhone Tutorial5–Views-Transition

January 3rd, 2010 by aabhaanjan

This tutorial will focus on transitioning from one view to another. We will be utilizing Windows based Application to move from one view to another view.

In this tutorial you will learn:

  • Add A Windows Based Application.
  • Add a View Controller
  • Add a class to create Array
  • Set Up The Transition To The View
  • Connect The View To The Code

Creating a New Window Based Application

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this:

Make sure Application is selected under iPhone OS and then select Windows-Based Application. Click Choose… It will ask you to name your project. Type in “Tutorial 3 –transition between view” and let’s get started.

Now, all of these files together create a basic program.When you click Go ahead and click on the Build and Go button ,It display the bellow

You will see the iPhone simulator start and your program will launch.

Use Array to display Fresa Content in First View:-

Process to create Array class :-

  1. For Creating Array for fresa application à GO TO FILE à ADDà New Fileàand Select Objective C –Class and enter the name of file .The Screen will look like this

2. Now start by opening FresaCellView.h. This is the class for view controller that Apple display fresa content to main view .

Here you are creating the instance of Label and image to display the content to label and Picture to Image view control and you are creating method .

  1. Now start FresaCellView.m.

Here you have created the class and initialize the label.

  1. Now you want to utilize this class , you have to create a new table view controller class. For Creating New Viewcontroller Class . All of the functions you see already created in here are functions that have been overridden from the Table View super class.

Process to create viewController Class

  1. GO TO File à ADD à New File àSelect Objective C Class àEnter the name àFresaTableViewController.

Automatically two file will created .

  1. FresaTableViewController.h
  2. FresaTableViewController.m

Now you have to write code to utilize the FresaCellView Class .

Here you have to import fresaCellView class in FresaTableViewController.h .

This is fresatableViewController.m file . here you have to define your fresa content , Which will be appear in simulator

Since we are editing a table, all of these functions will be related to editing a table. So find the function called numberOfRowsInSection.

This function tells the application how many rows are in our table. Currently, it returns 0. Let’s change that to return no of content defined in array

.

Now go down to the function called cellForRowAtIndexPath. This function gets called once for every row. This is where we define what content to display in a given row. In this case we want the row to be a string that says.

What this function is doing is creating a new cell object and returning it. The code between the i(cell==null) block checks to see if we have created a cell before, if not build a new cell, otherwise use the one we created before. This helps in performance so we don’t need to build new cells each time we visit this function. So right before the // Set up the cell comment add the following code:

[call setLabelText:[arryData objectAtIndex:indexPath.row]];

Now come to the main file Tutorial2_NsArrayAppDelegate.h and Tutorial2_NsArrayAppDelegate.m .

For displaying view to the main window you have to create navigationControll to mapped with the view.

Now You have to create User Interface to display the fresa content .

Process to Create User Interface View :-

1.GOTOà ResourceàAdd File àView UIàAdd Label and ImageView

Now most important part to mapping with label and image. You have to mapped with the class .Here description text properties which is defined in fresaCellView.h class is mapped with label .

Process for User Interface :

  1. Now open Window.xib file.
  2. Drag and drop Navigation control to mainwindow.xib .
  3. Select Tutorial2_NsarrayAppdelegate class from Class identity.
  4. Now most important part here is that, You have to mapped navigationcontroller with the navigationControlle tab which you have selected from Library.

5. Now Call FresatableViewcontroller.xib file in View Controller properties . the screen will be look like this .

After Mapping Click the Build and Go button again to launch the iPhone simulator. You should see screen look like this and your content will display on the screen

Now here you want to transition between one view to another view . When you will click the Fresa menu the data or content of the respective menu will be display to other view . For displaying the content or description of the menu You have to follow the following process .

Add A New View

We will now add the view that we will be transitioning to. Click on. Once inside Interface Builder click on File -> New and select View.

It will add a blank View to your project mention the name nextviewcontroller . For now, we will keep it simple. Go ahead and drag a new Label on to the View.

Let’s save the view. Click File -> Save. Call it NextViewController.

Add A View Controller

Now we need to create a NextViewController class. This class will be used to connect the view that we just created to our code. Inside of Xcode click File -> New File… Select UIViewController subclass and click Next.


Name it NextViewController and make sure “Also create “NextViewController.h” “ is checked. Click Finish to continue. This will add the new ViewController to your project.

Set Up The Transition To The New View

Open up Tutorial2_transitionAppdelegate.h and add the following code:

Now go and Run

When you click on “ Fresa menu” it should transition to:

Notice the back button at the top with the text “Fresa”.

Tags: , , , , , , , , , , , , , , , , , , ,

IPhone Tutorial4-View Based(Using Array)

January 3rd, 2010 by aabhaanjan

Hi All In this tutorial I would like to describe how to used NSArray to display the content I am going to show you the simplest way to create a list of content using array .

You will learn how to:

  • Create a Windows Based Application
  • Create Class to display fresa menu .
  • Create User Interface to display the menu .

Creating a New Windows-Based Application

Open Xcode

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this:

Make sure Application is selected under iPhone OS and then select Windows-Based Application. Click Choose… It will ask you to name your project. Type in “Tutorial 2 -NSArray” and let’s get started.

Now, all of these files together create a basic program.When you click Go ahead and click on the Build and Go button ,It display the bellow

will see the iPhone simulator start and your program will launch.

http://www.dremsus.com/welcome/3.JPG

http://www.dremsus.com/welcome/3.JPG

Use Array to display Fresa Content in View:-

Process to create Array :-

  1. For Creating Array for fresa application à GO TO FILE à ADDà New Fileàand Select Objective C –Class and enter the name of file .The Screen will look like this
http://www.dremsus.com/welcome/1.1.JPG

http://www.dremsus.com/welcome/1.1.JPG

2. Now start by opening FresaCellView.h. This is the class for view controller that Apple display fresa content to main view .

http://www.dremsus.com/welcome/1.2.JPG

http://www.dremsus.com/welcome/1.2.JPG

Here you are creating the instance of Label and image to display the content to label and Picture to Image view control and you are creating method .

  1. Now start FresaCellView.m.
http://www.dremsus.com/welcome/fresaarray/fresa3.JPG

http://www.dremsus.com/welcome/fresaarray/fresa3.JPG

Here you have created the class and initialize the label and imageView.

  1. Now you want to utilize this class , you have to create a new table view controller class. For Creating New Viewcontroller Class . All of the functions you see already created in here are functions that have been overridden from the Table View super class.

GO TO File à ADD à New File àSelect Objective C Class àEnter the name àFresaTableViewController.

Automatically two file will created .

  1. FresaTableViewController.h
  2. FresaTableViewController.m

Now you have to write code to utilize the FresaCellView Class .

http://www.dremsus.com/welcome/fresaarray/fresa5.JPG

http://www.dremsus.com/welcome/fresaarray/fresa5.JPG

Here you have to import fresaCellView class in FresaTableViewController.h .

http://www.dremsus.com/welcome/fresaarray/fresa6.JPG

http://www.dremsus.com/welcome/fresaarray/fresa6.JPG

This is fresatableViewController.m file . here you have to define your fresa content , Which will be appear in simulator

Since we are editing a table, all of these functions will be related to editing a table. So find the function called numberOfRowsInSection.

http://www.dremsus.com/welcome/4.JPG

http://www.dremsus.com/welcome/4.JPG

This function tells the application how many rows are in our table. Currently, it returns 0. Let’s change that to return no of content defined in array

Now go down to the function called cellForRowAtIndexPath. This function gets called once for every row. This is where we define what content to display in a given row. In this case we want the row to be a string that says.

http://www.dremsus.com/welcome/5.JPG

http://www.dremsus.com/welcome/5.JPG

What this function is doing is creating a new cell object and returning it. The code between the i(cell==null) block checks to see if we have created a cell before, if not build a new cell, otherwise use the one we created before. This helps in performance so we don’t need to build new cells each time we visit this function. So right before the // Set up the cell comment add the following code:

[call setLabelText:[arryData objectAtIndex:indexPath.row]];

http://www.dremsus.com/welcome/fresaarray/fresa8.JPG

http://www.dremsus.com/welcome/fresaarray/fresa8.JPG

  1. Now come to the main file Tutorial2_NsArrayAppDelegate.h and Tutorial2_NsArrayAppDelegate.m .

For displaying view to the main window you have to create navigationControll to mapped with the view.

Now You have to create User Interface to display the fresa content .

Process to Create View :-

1.GOTO –> Resource –>Add File –>View UI –>Add Label and ImageView

Now most important part to mapping with label and image. You have to mapped with the class .Here description text properties which is defined in fresaCellView.h class is mapped with label .

Process for User Interface :

  1. Now open Window.xib file.
  2. Drag and drop Navigation control to mainwindow.xib .
  3. Select Tutorial2_NsarrayAppdelegate class from Class identity.
  4. Now most important part here is that, You have to mapped navigationcontroller with the navigationControlle tab which you have selected from Library.

5.Now Call FresatableViewcontroller.xib file in View Controller properties . the screen will be look like this .

After Mapping Click the Build and Go button again to launch the iPhone simulator. You should see screen look like this and your content will display on the screen:

Tags: , , , , , , , , , , , , , , , , , , ,

IPhone Tutorial2 -(View Based Application)

December 26th, 2009 by aabhaanjan

Hi All I will show you how to create “Welcome ” application using the interface builder . There are many way to create application in IPhone .IN this tutorial no need to write code at all .

Create a new View based Project

Process to Create Application

  1. Open XCode for creating a new View – Based Application .

Go -> File ->New Project and select View Based Application and name the project Welcome

I have already described in earlier tutorial,When you are creating application there are some additional file which I have already described . Here you can only see one view at a time, you will need to create a new view for each screen in your application.

Go ahead and click Build and Go.

Process to Create Application

1. Open XCode for creating a new View – Based Application .

2.Go -> File ->New Project and select View Based Application and name the project Welcome

I have already described in earlier tutorial,When you are creating application there are some additional file which I have already described . Here you can only see one view at a time, you will need to create a new view for each screen in your application.

Go ahead and click Build and Go.

The program will compile and launch the iPhone Simululator. Your screen should look something like this.

you want to display “WelCome to IPhone”. So let’s add some UI components to our view to make it more interesting. To do this we will be editing WelcomeViewsViewController.xib . A file with the .xib extension is known as a nib file. These files open with Interface Builder and are where you define the look and feel of your application. Apple is nice enough to have provided us with one.

Once you open Interface Builder, you should see a few different windows… You should see a blank window that says View. If not click the View icon in the smaller box. This is the main window we will be editing.

Just click on the one’s you want and drag them on to your view. Make sure you at least use a Label.

Executing the Code

Go ahead and click Build and Go again to launch the iPhone Simulator. Your screens should look something like this:

Once you open Interface Builder, you should see a few different windows… You should see a blank window that says View. If not click the View icon in the smaller box. This is the main window we will be editing.

Just click on the one’s you want and drag them on to your view. Make sure you at least use a Label.

Executing the Code

Go ahead and click Build and Go again to launch the iPhone Simulator. Your screens should look something like this:

If you have any questions, feel free to leave them in the comments.

Tags: , , , , , , , , , , , , , , , , , , , , ,

iPhone Tutorial1 -UITableView(Navigation Based)

December 26th, 2009 by aabhaanjan

Hi All In this tutorial I would like to discuss about how to create IPHONE Application . I will discuss you to creating a simple “Welcome to IPHONE” application using a UITableView. I am going to show you the simplest way to create IPhone Application .

You will learn how to create navigation based application :-

1.Create a New navigation -based Application

2. Learn About the Default Files

Process to Create Navigation based application :-

1. Open Xcode

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this

Make sure Application is selected under iPhone OS and then select Navigation-Based Application. Click Choose…

Learn About the Default Files

When you will enter the name of your project and click the button .There will be few files that get added to your project. I would like to discribe about the file . What is the functionality of file .So Have a look of each file .

CoreGraphics.framework, Foundation.framwork, UIKit.framework – These are a set of library functions provided by Apple that we use in our application. We use these as includes similar to any other language that includes library functions.

  1. Welcome.app – This is your app that gets installed on the iPhone.
  2. WelCome_Prefix.pch – This is another include file that gets compiled separately from your other files so you don’t need to include it on each file. It contains some code to include the data inside the frameworks.
  3. WelcomeAppDelegate.h – This is a header file that contains all of our definitions for variables that we will be using. It’s very similar to a header file in C or C++;
  4. WelcomeAppDelegate.m – All of the magic starts here. Consider this file our starting point for execution. The main.m file invokes this object.
  5. Info.plist – This contains various meta information about your program.Even you can add main image in plist file.
  6. main.m – Like most programming language, this file contains our main function. This is where execution begins. The main function basically instantiates our object and starts the program. You shouldn’t need to edit this file.
  7. MainWindow.xib – This contains the visual information of our main window. If you double click on it, it will open in a program called “Interface Builder”.
  8. RootViewController.h, RootViewController.m – These are files for a view controller that gets added to our main window. Basically, Apple has already created a simple interface when you clicked on Navigation-Based Application. Since most navigation-based applications use a Table View, Apple has provided it for us to use.
  9. RootViewController.xib – This is a view that Apple has provided that emulates a table. It has rows and columns. We will be displaying our “Welcome” text inside one of these rows

Now, all of these files together create a basic program.When you click Go ahead and click on the Build and Go button ,It display the bellow

Update the UITableView Cells to Display “WelCome” Text

Let’s write some code

Start by opening RootViewController.m. This is the view controller that Apple added to our main view. All of the functions you see already created in here are functions that have been overridden from the Table View super class. Since we are editing a table, all of these functions will be related to editing a table. So find the function called numberOfRowsInSection.

This function tells the application how many rows are in our table. Currently, it returns 0. Let’s change that to return 1.

Now go down to the function called cellForRowAtIndexPath. This function gets called once for every row. This is where we define what content to display in a given row. In this case we want the row to be a string that says “WelCome to IPhone”.

What this function is doing is creating a new cell object and returning it. The code between the i(cell==null) block checks to see if we have created a cell before, if not build a new cell, otherwise use the one we created before. This helps in performance so we don’t need to build new cells each time we visit this function. So right before the // Set up the cell comment add the following code:

[cell setText:@”Welcome To IPhone”];

We are basically calling the setText method of the cell object and pass in the string “WelCome to IPhone”. Here string begins with @ sign .

Click the Build and Go button again to launch the iPhone simulator. You should see screen look like this and youe content “welcome to iphone” will display on the screen:

If you have any question and doubt fell free to let me know .

Tags: , , , , , , ,