Programming/Non programming

Monday, July 19, 2010

Blackberry:How to create new project through Blackberry JDE?

Blackberry:

How to create new project through Blackberry JDE:

1. Launch Blackberry JDE
2. Click on File menu->New->Workspaces
3. Provide Workspace name and location where you want to store it.
    It will create a workspace now.
4. Right click the workspace and click "New project in ..."
    It will create the project now.
5. Right click and click "Create new file in Project"
   It will create the java file.
Go ahead and add your code.

That's all !

Thank you very for reading this.

Prabakar M.P.
Senior Systems Analyst

Tuesday, July 6, 2010

Android:Create New Project in Android using Eclipse

Android:


Create New Project in Android using Eclipse

1. Launch Eclipse
2. Click on "New" menu item and choose "New Android Project"
3. Type "Project Name: ". For ex: HelloAndroid
    Make sure, "Create new project in workspace"
    and
    "Use default location" is enabled.
4. Select any "Build Target" for ex: Android 1.6 or Android 2.0 something like whatever you need..
5. Type Application name: For ex: "HelloAndroid"
6. Type Package Name in this format: For ex:    com.yourcompanyname.HelloAndroid
7. Enable "Create Activity" and type name as project name: For ex: HelloAndroid
8.Type "Min SDK Version" .
   NOTE: This is an Integer indicates minimum level API version. If you are not sure to type this, See the "API Level" value mentioned in "Build Target" tab when you are creating new android project screen. Please note it should not be Float value like "2.6" something like that, it should be real integer like "3" or something like that.
9. Click "Finish" button to complete creating New Android Project.

M.P.PRABAKR
Tech Lead.
Mobile software development

Monday, April 19, 2010

Objective C versus C++

Objective C versus C++


Here are the main points of difference between C++ and Objective-C;

  • Objective C is geared towards Run-time decisions and C++ is geared towards Compile-time decisions.
  • C++ comes with large standard libraries which included several container classes and Objective C includes only object-oriented features to C.
  • In C++, variables are called attributes and functions called member function and in Objective-Cits called as instance data and methods.
  • In C++, attributes and methods are inside the braces of the class and In Objective-C, these are not mixed, attributes are declared in braces and methods are declared in outside of the braces. Class implementation will be in @implementation block and class declaration will be in @interface instead of @class.
  • Major difference is with Objective-C and C++ is, It is possible to implement a method without  declaring that in interface in Objective-C. These methods are called Well-Known methods. All methods are virtual, so there is no keyword virtual exits in Objective-C.
  • In C++, two functions can have same name as long as their parameters have different parameters like below.    
int func1(int);   
int func1(float);


In Objective-C, all functions are C, it cannot be overloaded. But if the parameter labels are differe
nt, then it is acceptable to use the same function name for two different. Something like below:

int func1:(int) param1 :(int) param2;
int func1:(int) param1 myLabel:(int) param2;
  • The following modifiers can be added in C++ to the prototype of a function. But that is not possible in Objective-C:
const, 
static (it is done by using "+" and "-"), 
virtual (keyword is useless because all are virtual), 
friend(there is no "friend" notion), throw.

  • Objective-C supports Single Inheritance but not Multiple Inheritance instead it has protocols.
  • In C++, class can be derived from one or several other classes using public, private or protected mode. In this, super class can be accessed using scope resolution operator (::).  In Objective-C, only one class only derived from public mode. Super class can be accessed using (false) keyword "super" like in Java.


Cheers!

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

Friday, April 16, 2010

C++:Polymorphism

C++ Concept: Polymorphism (also includes UPCASTING, VTABLE, "late-binding" or "dynamic-binding", Pure Virtual Function, )


"Polymorphism" is one of the strongest OOP(Object Oriented Programming) concept in C++. It is the ability to redefine the methods for derived classes. It can be said like call different function with one type of function call. Using "Virtual" function, this polymorphic concept is being done, so the base class function must be declared as "virtual".

Example I

1. Consider there is a base class as "Shape".
2. Consider there may be derived classes such as Circles, Rectangles and Triangles.
3. There could be a method called "area(...)" as "virtual" method. It acts as "Polymorphism". Because it could be called in all the three derived classes, but it will give you the correct results for every classes as it needed.

Example II

1. Consider a base class called "base"


class base {
        
      public:
         void func()
         {
              cout<<"This is from base class";
         }
};


2.  Derived two classes from the base class like below:


class derived1 : public base
{
      public:
        void func ()
        {
              cout<<"This is from derived class1";
        }
};


class derived2 : public base
{
       public:
          void func()
          {
               cout<<"This is from derived class2";
          }


};


Note down all the classes has a function called "func()" as same:


You:
Does it mean polymorphism?


Me:
NO...........then Why and How?


Lets say i'm outputting the result as below which is a normal procedure:


void main()
{
        derived1 der1;
        derived2 der2;
        
        // The below concept till the END is called "UPCASTING" in c++
        base *b;
        b = &der1;
        b->func();
     
        b = &der2;
        b->func();
        // END
}


[ "UPCASTING" :-  Pointer of a base class to accept addresses of derived classes ]

The output will be:

"This is from base class"
"This is from base class"


You:
Why? What happened? You said "Polymorphism" mean different functions but one type of call etc. in this post initially? Why doesn't it happen here?


Me:
Compiler looks at the above code and calls the function which has type of pointer (base class) .
The earlier one doesn't handle "Virtual" function in the base class, so it is nothing but calling non-virtual functions normally. That's the reason, base class output will be called twice as seen in the above output.
I also said after sometimes, "Virtual" function is the one handles polymorphic logic. So check the below definitions.

3. Add function as "virtual" function in "base" class, which is very important here.


class base {
        
      public:
         virtual void func()
         {
              cout<<"This is from base class";
         }
};









Now, the output will be:

"This is from derived class1"
"This is from derived class2"



Now, we got the output properly. Why and How? "Virtual" function makes the Polymorphism now.

Now, the compiler looks at contents of the pointer. Hence it's addresses pointing to derived classes, it calls derived call functions properly.


But still compiler doesn't know which function to call at compile-time. It decides which function to call at Run-time with the help of VTABLE (described about it below). Compiler uses this table to find what is to be pointed and call the respective functions.
This concept is, compiler decides which function is to be called at Run-time, called "late-binding" or "dynamic-binding".



Pure Virtual Function:


You can realize from the above code is that, "base" class function is never being called. So, keep this body blank anyway like below. It is called "Pure Virtual Function".








class base {
        
      public:
         virtual void func()=0;  // Pure Virtual Function
};


One more point here is, if the base class has "Pure Virtual Function" (like the example just above), then object of that class cann't be created. The one can use only "derived1" and "derived2" and access virtual function (As per our examples mentioned above in void main() function).

When do need "Pure Virtual Function":

When a virtual function would not be needed to create base class object, then use base class method as Pure Virtual function, where we can't created an object on that.


How does the Virtual function work using VTABLE:


Every class has VTABLE where it stores the functions that it can access. Each class VPTR that can access VTABLE.


First check-out our virtual function code below






class base {
        
      public:
         virtual void func()
         {
              cout<<"This is from base class";
        }
       virtual void output()
       {
             cout<<"Final Output";
      }

};




class derived1 : public base
{
      public:
        void func ()
        {
              cout<<"This is from derived class1";
        }
};

class derived2 : public base
{
       public:
          void func()
          {
               cout<<"This is from derived class2";
          }

};




void main()
{
        derived1 der1;
        derived2 der2;
      
        base *b;
        b = &der1;
        b->func();
     
        b = &der2;
        b->func();
        b->output(); 

        derived1 der2;
        b = &der2;
        b->func();
        b->output();
}



VTABLE for the above code is below:


Base Pointers            Objects                                    VTABLES


b   ---------------     base(VPTR)                           --   &base:func()
                                                                                  &base:output()


b   ---------------     derived1 der1, der2(VPTR) --   &derived1:func()


b   ---------------    derived2 der2(VPTR)           --    &derived2:func()         


First VPTR is initialized by the compiler automatically from the constructor called in base class. The next VPTR are created for when virtual function to be called.
If the function is not present in the VTABLE, then it calls the base class method of the same function. Here is output() method called like that.




I hope this simple example explanation and code sample described above should help someone who are newbie to C++ language programming.







Cheers!

M.P.Prabakar
Senior Systems Analyst.


Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

Tuesday, April 13, 2010

iPhone OS 4.0

iPhone OS 4.0 features:


Pre-requisites:
     - iPhone SDK 4 beta requires Mac OS X v10.6.2 or later.
     - This software should only be installed on devices dedicated exclusively for iPhone OS 4 beta
        application development.
     - iPhone SDK 4 beta cannot be used for submitting applications to the App Store
     - iPhone OS 4 will only work with iPhone 3G, iPhone 3GS and 2nd, 3rd generation iPod touch. Not
       all features are compatible with all devices. Multitasking is available only with iPhone 3GS and 3rd
       Generation iPod touch.


Apple introduces excellent and nice features support in OS 4.0. Beta version of 4.0 SDK is currently available from developer.apple.com website, only for registered developers. This version supports to run only on iPhone and iPod, not on iPad.

Below are the brief explanations about iPhone OS 4.0 features.

I. Multi tasking

i)  Application can now able to run in the background from 4.0 onwards.
ii) Many of the tasks that you want to execute can now continue even after exiting the application to home screen.
iii) Background applications can still got terminated in certain cases like low-memory etc.
iv) NOTE: It is not supported for all the iPhone OS devices. If a device is not running iPhone OS 4.0 and later, or if the hardware is not capable of running applications in the background, the system reverts to the previously defined behavior for handling applications.
v) Multitasking is available only with iPhone 3GS and 3rd Generation iPod touch.
vi) The following are the seven multitasking is supported with this new SDK:
     -> Background Audio - Allows to run your audio continuously even after exit the application.
     -> Voice over IP - Allows to have VoIP calls and have conversation while using other apps.
     -> Background location - Monitor location when user moves between cell towers.
     -> Push notifications - Receive alerts from your remote servers even when your app is not running.
     -> Local Notifications - Alert user in schedules events and alarms using local notifications.
     -> Task finishing (after exiting your app too..) - App can keep running to finish the tasks even after
                                                                                 exit your app.
     -> Fast App Switching - Allow to leave your app and come right back to where you left.

II. Notifications

i) Existing push notifications which is relying on external server is not needed hereafter from 4.0 and generating the notifications locally is being possible with this new SDK.
ii) Scheduled notification is being possible with this new SDK.
iii) For setting notifications, your application is not needed to be running.

III. Event Kit

i)   It gives access to built-in Calendar events using through EventKit.framework.
ii)  It gives access to scheduled alarms and edit existing events.
iii) For editing and viewing events, Event Kit has provided EventKitUI.framework.

IV. Data Protection

  Data encryption/decryption option has provided during lock/unlock.

V. Core Telephony

i)  Cellular-radio based phone information can be interacted using CoreTelephony.framework.
ii) Cellular call notifications and get service provider information are all possible now.

VI. iAd

i)   You can use deliver-modal and banner-based advertisements in your application using this AdLib.framework.
ii)  One more advantage of this is, after showing Advertisements in browser (launched from your app), it will be able to then again come back to your application safely with the last interaction.
iii) You need to register with Apple's Ad service for this.

VII. Graphics and Multimedia

- Quick Look Framework:

  To show your downloaded contents in this framework view controller directly after downloading it from the network using QuickLook.framework.

- AV Foundation: (AVFoundation.framework)

i) It has been expanded from 3.0 SDK. It includes advanced features such as:

   Media editing,
   Movie capture,
   Movie playback (after exiting your applications too),
   Track management

- Assets Library:

  Assets Library framework (AssetsLibrary.framework) provides access to users' photos, videos, saved photos album.

- Image I/O: (ImageIO.framework)

   Give access to import and export image data and image metadata.

- Core Media: (CoreMedia.framework)
  
    It provides a low-level C interface for managing and playing audio-visual media in your application.

- Core Video: (CoreVideo.framework)

   It provides buffer and buffer pool support for Core Media.


Please read the http://developer.apple.com/ to have more informations on this and download the SDK.



Cheers!

M.P.Prabakar
Senior Systems Analyst.


Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

iPhone:Animate gif image in program

iPhone: 


How to animate an animated or non-animated Gif or any other images on iPhone development

Point to remember:

There is no possibility to directly apply an animated Gif or any other image in project resource and call UIImageView to animate it.

How do we achieve it?

There is a UIImageView property called 'animationImages', using which we can pass array of image frames and animated it as same as seeing gif animation on browser.

Steps:

1. Get your required animated gif image. Use some tools to extract that animated gif image to frame by frame images. I used Mac->Preview to launch my animated gif image, it will automatically show frames of images, choosing each one and do Save As to have frame of images in JPG format.

2. Add all the frame of gif images into your project resource folder in Xcode.

3. create an UImageView in your application screen.

4. Use the following code to make the animation:


UIImageView *myImageView;

myImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:firstImgStr],[UIImage imageNamed:secondImgStr], [UIImage imageNamed:thirdImgStr], [UIImage imageNamed:fourthImgStr], nil];

myImageView.animationDuration = 1.0f;
myImageView.animationRepeatCount = 0;
[myImageView startAnimating];
[myImageView release];


Run this code and you can see the animated gif doing animation on screen in your UImageView.
Note: I added just four frame of images there such as firstImgStr, secondImgStr etc. you can add how many frame of images that you require. 





Cheers!

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

Monday, April 12, 2010

iPhone:Localization support on iPhone development

iPhone:

How to support localization for your application on iPhone development

Here is the simple steps to achieve this:

1. Collect the text in whatever the languages that you are needed in.

2. Create any kind of project in Xcode.

3. Open the project folder through finder.

4. Create new folders called "en.lproj" for English language, "es.lproj" for Spanish language, "it.lproj" for Italian language, "ja.lproj" for Japanese language, "de.lproj" for Deutch language, under your project in finder.

5. Launch your project in Xcode.

6. Right click "Resources" folder and click on "Add"-> "New File".

7. In the 'choose template ....' section, look for "Other" section (which will be in the last), and Choose "Strings File" from the right side tab.

8. Name it as "Localizable.strings" and Save it under the folder "en.lproj"(which u created in step 4). Continue creating another "Localizable.strings" and Save it under the folder "es.lproj"... like-wise continue doing it upto how many *.lproj you have created. In my example, i created "Localizable.strings" and Save it under upto "de.lproj" folder.

[Xcode is smart enough to figure out the folder and sitting there properly, which you could see there..]

9. Handling Localization here is matter of adding two values. One is "Key" and other is "Value". Format is looking like
"Key" = "Value";

Let us see the below sample of adding Key-Value pair from the resource.

10. Choose "en.lproj" in Xcode project resource and add welcome text in this
format ->  "WelcomeKey" = "Welcome!"

      Same for this in Italian language will be,  "WelcomeKey" = "Benvenuto!"
      Same for this in Spanish language will be,  "WelcomeKey" = "Bienvenida!"

Likewise add the text in the languages whatever you want.

11. We will see next how to access this in code:

       It is pretty simple, it does by an API called "NSLocalizedString("key", "comment")";


We can leave second parameter "comment" parameter blank as it does serve a purpose of generating the strings file automatically.

For example, If i want to localize the above mentioned Welcome text and put in a label. Here is the sample below.

myLabel.text = NSLocalizedString(@"WelcomeKey",  "");


Result will be,

Whenever user chooses the language on iPhone from settings, it takes welcome text for that languages which we added in our *.lproj file and show in label. If the text is not available for particular chosen language, then it picks text from the second language in the list.

That's it to achieve this!!! If any doubts or comments. Please leave here.

Thank you.


Cheers!

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

Tuesday, April 6, 2010

iPhone:Handling SQLite database in iPhone development

iPhone:

How to handle SQLite database on iPhone development:


I have seen somewhere that people was struggling to add and handle sqlite database on iPhone development. I would like to help them on giving simple explanation with a project sample here.

If you might have seen some more details easily than this blog in somewhere else, then please don't hesitate  to follow up there wherever you are convenient.

Here you go friends !!!

I. SQLite:

i) Creating a sqlite database using Terminal sql command in "Documents" folder.

   In Terminal,

   go to Documents directory and create a folder first.

my-macbook:~ myname$ cd Documents
  my-macbook:Documents myname$ mkdir MPSQLiteMainFolder

   Create a sqlite database there. I named it as "MPsqlitedb"

  my-macbook:Documents myname$ cd MPSQLiteMainFolder
my-macbook:MPSQLiteMainFolder myname$ sqlite3 MPsqlitedb  // for creation

   After applying the above creation command, you should now be in the sqlite command: (like below)

SQLite version 3.4.0
Enter ".help" for instructions
sqlite>
   Since database have been created, we need to create a table and insert data into it. This will be based on your requirement. I am going to create a table with 3   
   parameters required for me. And then insert country name, some description and flag image there. Please see example below.
// Table creation. Table name "mysqlitetable"
sqlite> CREATE TABLE mysqlitetable (id INTEGER PRIMARY KEY, countryname VARCHAR(50), nationalanthem TEXT, cntryflagimg VARCHAR(255) );
// inserting data into it.
sqlite> INSERT INTO mysqlitetable(countryname,nationalanthem,cntryflagimg) VALUES ('INDIA', 'India is my country. I found one of the fast growing country in the     world','http://flagpedia.net/data/flags/normal/in.png');
sqlite> INSERT INTO mysqlitetable(countryname,nationalanthem,cntryflagimg) VALUES ('UNITED STATUS', 'United Status is one of the well grown country in the     world','http://flagpedia.net/data/flags/normal/us.png');
sqlite> 


After done this, if you have doubt whether you have created database successfully or not, then follow the command to make sure it is done perfectly.

SELECT * FROM mysqlitetable;


Now you have created a sqlite database and also inserted data into it. Next, we will see how can we access this database in iPhone code and handle it with this simple example.


II. Project




1. Create a navigation based project in Xcode.

After project has created,

2. Add sqlite library into our project as we are going to handle sqlite database in our code.

   To do that,

   1. Right click your project "Framework", and choose "Add existing framework"
   2. Take the path of, "Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS3.0SDK/usr/lib/libsqlite3.dylib"

3. We have to also add our database(which we created above as "MPsqlitedb".

 To do that,

   1. Right click your project "Resources", and choose "Add existing files"  
   2. Choose the sqlite database file which you created as "MPsqlitedb" from Documents folder.

Now, the time to add code:

1. What we will do is, we will create a structure(here it is Class, we will name it as " CountryDetails ") where-in maintains three variables for countryname, nationalanthem and cntryflagimg..

2. In AppDelegate, we read the database which we created. Read values will be added in CountryDetails class and CountryDetails class object will be added its combined data into a mutable array called "DataCollector", which will act as storing multiple CountryDetails class object.

3. Now the data is ready, we will show "name" of the country first in TabelView rootviewcontroller by accessing this data.

4. After the name is shown, we will have to add another view controller called "DetailsViewController", where-in our data country national anthem description and flag image will be shown there by accessing them from the CountryDetails objects.

Code:

Here is the code:


// AppDelegate.h file ########################################################

#import
#import

@interface MySQLLiteSampleAppDelegate : NSObject {
    
    UIWindow *window;
    UINavigationController *navigationController;
NSString *databaseName;
NSString *databasePath;
NSMutableArray *elements;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@property (nonatomic, retain) NSMutableArray *elements;

-(void) CreateDatabaseIfRequired;
-(void) ReadAndExtractDatabase;

// AppDelegate.m file ########################################################

#import "MySQLLiteSampleAppDelegate.h"
#import "RootViewController.h"

#import "CountryDetails.h"

@implementation MySQLLiteSampleAppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize elements;

#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    
    // Our database name
databaseName = @"MPsqlitedb.sql";
// Get the document directory path and append databaes name to the path..
NSArray *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [docsPath objectAtIndex:0];
databasePath = [docDir stringByAppendingPathComponent:databaseName];
// Add the database into the path if it is already not exists.
[self CreateDatabaseIfRequired];
// Read the database and extract the contents..
[self ReadAndExtractDatabase];
// Override point for customization after app launch
[window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}

-(void) CreateDatabaseIfRequired {
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL bAvailable = [fileManager fileExistsAtPath:databasePath];
// database already exists so just exit from here..
if ( bAvailable ) return;
// if not exists copy the db into the path..
NSString *databaseAtResourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databaseAtResourcePath toPath:databasePath error:nil];
[fileManager release];
}

-(void) ReadAndExtractDatabase {

sqlite3 *database;
elements = [[NSMutableArray alloc] init];
// Open database
if ( sqlite3_open([databasePath UTF8String], &database) ==SQLITE_OK )
{
const char *sqlstatement = "select * from mysqlitetable";
sqlite3_stmt *combiledstatement;
printf( "could not prepare statemnt: %s\n", sqlite3_errmsg(database) );
if ( sqlite3_prepare_v2(database, sqlstatement, -1, &combiledstatement, NULL)==SQLITE_OK )
{
while ( sqlite3_step(combiledstatement)==SQLITE_ROW )
{
NSString *name = [NSString stringWithUTF8String:(char*) sqlite3_column_text(combiledstatement, 1)];
NSString *nationalAnthemDesc = [NSString stringWithUTF8String:(char*) sqlite3_column_text(combiledstatement, 2)];
NSString *image = [NSString stringWithUTF8String:(char*) sqlite3_column_text(combiledstatement,3)];
CountryDetails *detObj = [ [CountryDetails alloc]initDetails:name :nationalAnthemDesc :image ];
[elements addObject:detObj];
[detObj release];
}
}
// release the combiled statement
sqlite3_finalize(combiledstatement);
}
sqlite3_close(database);
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}


// RootViewController.h file ########################################################

#import "DetailViewController.h"

@interface RootViewController : UITableViewController {
DetailViewController *detViewController;
}

@property (nonatomic, retain) DetailViewController *detViewController;

@end


// RootViewController.m file ########################################################

#import "RootViewController.h"
#import "MySQLLiteSampleAppDelegate.h"
#import "CountryDetails.h"

@implementation RootViewController
@synthesize detViewController;

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = @"Country details";
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
MySQLLiteSampleAppDelegate *appDelegate = (MySQLLiteSampleAppDelegate*) [ [UIApplication sharedApplication] delegate];
    return appDelegate.elements.count;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
// Configure the cell.
MySQLLiteSampleAppDelegate *appDelegate = (MySQLLiteSampleAppDelegate*) [ [UIApplication sharedApplication] delegate ];
CountryDetails *contryDet = (CountryDetails*) [appDelegate.elements objectAtIndex:indexPath.row];
[cell setText:contryDet.countryname];
    return cell;
}

// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MySQLLiteSampleAppDelegate *myAppDelegate =  (MySQLLiteSampleAppDelegate *) [ [UIApplication sharedApplication] delegate ];
CountryDetails *contryDet = (CountryDetails *) [myAppDelegate.elements objectAtIndex:indexPath.row];
    // Navigation logic may go here -- for example, create and push another view controller.
detViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detViewController animated:YES];
detViewController.title = [contryDet countryname];
[detViewController.natAnthemDescView setText:[contryDet nationalanthem] ];
// download image from url
NSData *imgdata = [NSData dataWithContentsOfURL:[NSURL URLWithString:[contryDet cntryflagimg] ] ];
UIImage *flagImage = [ [UIImage alloc] initWithData:imgdata];
detViewController.flagImageView.contentMode = UIViewContentModeScaleAspectFit;
//detViewController.flagImageView.frame = CGRectMake(329, 460, 329, 186);

[detViewController.flagImageView setImage:flagImage ];
[detViewController release];
}

- (void)dealloc {
    [super dealloc];
}


// CountryDetails.h file ########################################################

#import

@interface CountryDetails : NSObject {
NSString *countryname;
NSString *nationalanthem;
NSString *cntryflagimg;
}
@property (nonatomic, retain) NSString* countryname;
@property (nonatomic, retain) NSString* nationalanthem;
@property (nonatomic, retain) NSString* cntryflagimg;

-(id) initDetails : (NSString*) cntryname :(NSString*) natAnthDetail :(NSString*) flagImage;


// CountryDetails.m file ########################################################


#import "CountryDetails.h"


@implementation CountryDetails
@synthesize countryname;
@synthesize nationalanthem;
@synthesize cntryflagimg;

-(id) initDetails : (NSString*) cntryname :(NSString*) natAnthDetail :(NSString*) flagImage
{
self.countryname = cntryname;
self.nationalanthem = natAnthDetail;
self.cntryflagimg = flagImage;
return self;
}

@end

// DetailViewController.h file ########################################################

#import

@interface DetailViewController : UIViewController {
IBOutlet UITextView *natAnthemDescView;
IBOutlet UIImageView *flagImageView;
}
@property (nonatomic, retain) IBOutlet UITextView *natAnthemDescView;
@property (nonatomic, retain) IBOutlet UIImageView *flagImageView;

@end

// DetailViewController.m file ########################################################

#import "DetailViewController.h"


@implementation DetailViewController
@synthesize natAnthemDescView;
@synthesize flagImageView;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


##### Add a detail view controller.xib file (which might get added when you added the view controller class itself). I named it as DetailViewController.xib

** Add a TextView and UIImageView there and link them all.



Please drop your comments if it really helped you in someway....

Thank you.


Cheers!

M.P.Prabakar
Senior Systems Analyst.



Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..