How to use UIPopoverController in iPad programming?

This post deals with using UIPopoverController in iPad programming..

 

UIPopoverController is an iPad specific controller. UIPopoverController is not actually a ViewController in itself but it manages the presentation of view controllers. Popovers provide a lightweight way to present or gather information from the user and are commonly used in the following situations:

 

  • To display information about an object on the screen.
  • To manage frequently accessed tools or configuration options
  • To present a list of actions to perform on objects inside one of your views
  • To present one pane from a split view controller when the device is in a portrait orientation

Now we will see how we can make a UIPopoverController as shown above

We will take two view controllers for this tutorial

The first view controller will be popoverViewController and second view controller will be popViewController

The left pane of Xcode will look something like this

Now first come to popViewController.h and write the following code as highlighted

 

 

“delegate” property  will be assigned the object of popoverViewController class. So popoverViewController object will have the implementation of “-(void) dismiss:(popViewController *) controller;”. This method will be used to dismiss UIPopoverController. Also this is the view controller class which will be presented as a popover on the press of a button.

 

Open popViewController .xib, drag a table view on it as shown below and make the UITableViewDataSource and UITableViewDelegate connections

 

 

The above popViewController’s view will be shown as a popover and will change the value of the label in popoverViewController’s view on the selection of a row.

 

Now come to popViewController.m file

 

Populate the array with three values in viewDidLoad method

 

array=[[NSArray alloc] initWithObjects:@"JOHN",@"MIAMI",@"DEAN",nil];

Now write the following delegation methods of table view

 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

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

	return [array count];
}
- (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];
	}

	cell.textLabel.text=[array objectAtIndex:(indexPath.row)];
	return cell;
	}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	popoverViewController *p=(popoverViewController *)self.delegate;
	UILabel *label;
	label=p.label;

	label.text=[array objectAtIndex:indexPath.row];
	[self.delegate dismiss:self];
	NSLog(@"hello");

}

 

As we can see from the above code that the popover, which contains the content of popViewController class, will be containing three rows. Property delegate references popoverViewController object because it acts as the delegate for popViewController and implements “-(void) dismiss:(popViewController *) controller;” method as said above. This method will contain the code to dismiss the popover. So on selection of row, the value of the label in popoverViewController will be changed to the row’s value and popover will be dismissed.

 

Now come to popoverViewController.h file and write the following highlighted code

 

As this class acts as the delegate for popViewController class, so it implements popViewControllerDelegate. UIPopoverController’s object popover will be used to represent the content of popViewController class in popover style A label will be attached in popoverViewController.xib file which will change value on selection of row in popover.”pop:” method will be fired when bar button will be pressed and will show the popover.

 

Now come to popoverViewController.xib. Drag label and barbutton, and make connections as shown

 

 

Now open popoverViewController .m file

 

Implements the pop: method as shown below

 

-(IBAction)pop:(id)sender
{
	popViewController *pop=[[popViewController alloc] initWithNibName:@"popViewController" bundle:nil];
	pop.delegate=self;

	UIPopoverController* aPopover = [[UIPopoverController alloc]initWithContentViewController:pop];

	[pop release];
	self.popover = aPopover;

	self.popover.popoverContentSize=CGSizeMake(300, 500);
    [aPopover release];
	[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

 

In the above code we made a popViewController object which will be presented in a popover style with the help of UIPopoverController object. We set the “self” object as the delegate for popViewController object. After this we set the popover size by using property “popoverContentSize”. At last we display the popover.

Implement the delegate method “-(void) dismiss:(popViewController *) controller;”

 

-(void) dismiss:(popViewController *) controller
{
	[self.popover dismissPopoverAnimated:YES];
}

The above method will dismiss the popover

Save and build the application. Output is as shown below

 

Just click some row and you will see the value of label changing

The new Xcode 4 – Intelligent enough!

The new Xcode 4 – Intelligent enough!

Apple has launched the new Xcode 4 for the iOS Application Developers. It is for sure that the developers are going to love it because of its awesome features. Lets have a look at some of its new features.

What’s new in Xcode 4

 

The tools in Xcode 4 are redesigned to work faster and smoother. It has become more helpful, and it not only tells you error but also fix it for you.

 

Some of the new features which you will notice at first….

 

Single Window

Yes, the Xcode 4 is a single window development environment which combines Interface builder in the same window in which you write code.

 

Interface Builder is Built-in

There is no seperate application called interface builder. Infact, interface builder is integrated with Xcode. Selecting a .xib file will directly open editor in Xcode. You can drag connections directly from UI design to source code. If your code is not ready with actions and outlets then just drag connection to empty space in source code and Xcode 4 will define outlets and actions for you.

 

Assistant

This is another useful addition in Xcode4. If you make some changes in a source file then assistant will help you in determining which other source files need to be checked, as you work.

 

Fix it

The Xcode 4 is an IDE which is intelligent enough, not only to report but also fix problem for you.

How to create iPhone/iPad applications and submit them to App Store

How to create iPhone/iPad applications and submit them to App Store

So today we are going to see how to create iPhone/iPad applications and then submit them to App Store. So basically we will be starting with the requirements first that we need to get us started.

Requirements for building iPhone application

 

Macintosh computer

You can build an iPhone application only on a Macintosh computer. Macintosh computers run Mac as their operating system, and are completely different from Windows. You cannot install Mac operating system on a Windows PC as it is hardware dependent. So guys if you own a Windows computer then get ready to shed some money for buying your new Mac. You will feel the difference between them from the day you start using Mac.

 

Xcode

Xcode is an integrated development environment developed by Apple. Applications for iPhone/iPad are developed using Xcode in Objective c language. You can download Xcode by registering on Apple’s developer website. Xcode is downloaded as a complete package which consists of a programming environment for writing codes, an Interface Builder for designing pages and an iPhone simulator for testing applications.

 

 

 

iOS Developer Program

Ok, this is not so good part as it involves some more expenditure after you buy your Macbook. Apple needs you to be enrolled in its developer program before you can start putting applications on app store for sale. There are two membership programs, depending on whether you are a company(iOS Developer program Enterprise – $299) or an individual(iOS Developer Program Standard – $99) you can select your membership. After you get registered you can submit your application for sale on app store.

 

 

Apple’s new iPad2 | Thinner, Lighter and full of great ideas

Apple’s new iPad2 | Thinner, Lighter and full of great ideas

Thinner, Lighter and full of great ideas

 

Hi guys, it seems that Steve Jobs went strict on iPad’s dieting schedule, the result is in front of us. iPad2 has got rid of those extra flanks. Well, after seeing it one can only say……How the hell it holds equipments which give us such a smooth performance, even better than its elder brother. Yes, you heard it right, it is 3 times slimmer and more powerful than iPad1. Infact, iPad2 is the slimmest tablet in the world and is powerful than every other tablet .Well, we don’t know about humans, but if we believe Apple Inc. then “Thinnest is the Fittest”.

 

Lets check out some of the new features added to iPad2….


Dual-core A5 chip

Two cores in one chip, means it can do twice the work
at once. It multitasks smoother and applications work
better.

 

 

Superfast graphics

With up to nine times increase in graphics power , game
playing and video viewing on iPad is smoother and more
realistic.

 

 

Two cameras

Designed for Facetime video calling so that you could
see your friend laughing from front camera, and share
your environment from the back camera.