How to add UINavigationController to UITabbarController Programatically?


Hi,

Today I am going to Explain you How to Add UINavigation Controller to UITabbarController.

  • When you add UIViewController to UIWindow Your Application become ViewControllerBase(SingleView) Application.
  • When you add UIViewController to UINavigationController your application become NavigationBased(Master-Detail) Application.
  • When you add UIViewController/UINavigationController to your UITabbarController Your application become Tabbased Application.

so here we are using the same concept that add your Navigation Controller to UITabbarController so you will get Push/Pop effect in UITabbar Controller.

//Initialize tabbar Controller and All Navigation Controllers are added into Tabbar Controller
self.tabbar = [[UITabBarController alloc] init];
NSArray *arrNVControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4, nil];

self.tabbar.viewControllers = arrNVControllers;

Download the sample code from Here

Advertisements

Custom Calender For iPad


Hi,

I have implemented Custom Calender Control for iPad which is bit simple to implement.

Step 1: Add the Listed File into your Project.(I have Provided  all Listed Files.)

1.CustomCalendar.h

2.CustomCalendar.m

3.CustomCalendar.xib

4.TdCalendarView.h

4.TdCalendarView.m

Step 2: Now your 70% Task is completed.You need to Integrate the Delegate Methods only.

#pragma mark – CalendarViewDelegate methods
-(void)monthChanged:(CFGregorianDate)currentMonth viewLeftTop:(CGPoint)viewLeftTop height:(float)height{

}
-(void)selectDateChanged:(CFGregorianDate)selectDate{
}

-(void)beforeMonthChange:(TdCalendarView *)calendarView willto:(CFGregorianDate)currentMonth{

}

For More info Please check this images.

Here i am attaching the sample code for the same.

How to add Email and Message in your native application?


Hi,

See new sample code “MessageComposer” which includes both Mail and Messages features.

This application shows how to target older OS versions while building with newly released APIs. It also illustrates how to use the MessageUI framework to edit and send email messages from within your application.

Tap the “Compose Mail” button to display an email composition interface if your device is running iPhone OS 3.0 or launch the Mail application, otherwise.

Step 1:

Add MessageUI.framework to your Application.Add this Header file to the .h file and Provide delegate of it as shown below.

#import <MessageUI/MessageUI.h>

#import <MessageUI/MFMailComposeViewController.h>

@interface MailComposerViewController : UIViewController <MFMailComposeViewControllerDelegate>

{

IBOutlet UILabel *message;

}

@property (nonatomic, retain) IBOutlet UILabel *message;

-(IBAction)showPicker:(id)sender;

-(void)displayComposerSheet;

-(void)launchMailAppOnDevice;

 

Step 2:Now write the code for mail.

-(IBAction)showPicker:(id)sender

{

// This sample can run on devices running iPhone OS 2.0 or later

// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later.

// So, we must verify the existence of the above class and provide a workaround for devices running

// earlier versions of the iPhone OS.

// We display an email composition interface if MFMailComposeViewController exists and the device can send emails.

// We launch the Mail application on the device, otherwise.

 

Class mailClass = (NSClassFromString(@”MFMailComposeViewController”));

if (mailClass != nil)

{

// We must always check whether the current device is configured for sending emails

if ([mailClass canSendMail])

{

[self displayComposerSheet];

}

else

{

[self launchMailAppOnDevice];

}

}

else

{

[self launchMailAppOnDevice];

}

}

 

 

#pragma mark –

#pragma mark Compose Mail

 

// Displays an email composition interface inside the application. Populates all the Mail fields.

-(void)displayComposerSheet

{

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

 

[picker setSubject:@”Hello from Ankit Vyas!”];

// Set up recipients

NSArray *toRecipients = [NSArray arrayWithObject:@”first@example.com”];

NSArray *ccRecipients = [NSArray arrayWithObjects:@”second@example.com”, @”third@example.com”, nil];

NSArray *bccRecipients = [NSArray arrayWithObject:@”fourth@example.com”];

 

[picker setToRecipients:toRecipients];

[picker setCcRecipients:ccRecipients];

[picker setBccRecipients:bccRecipients];

 

// Attach an image to the email

NSString *path = [[NSBundle mainBundle] pathForResource:@”rainy” ofType:@”png”];

NSData *myData = [NSData dataWithContentsOfFile:path];

[picker addAttachmentData:myData mimeType:@”image/png” fileName:@”rainy”];

 

// Fill out the email body text

NSString *emailBody = @”It is raining in sunny California!”;

[picker setMessageBody:emailBody isHTML:NO];

 

[self presentModalViewController:picker animated:YES];

[picker release];

}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.

– (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

{

message.hidden = NO;

// Notifies users about errors associated with the interface

switch (result)

{

case MFMailComposeResultCancelled:

message.text = @”Result: canceled”;

break;

case MFMailComposeResultSaved:

message.text = @”Result: saved”;

break;

case MFMailComposeResultSent:

message.text = @”Result: sent”;

break;

case MFMailComposeResultFailed:

message.text = @”Result: failed”;

break;

default:

message.text = @”Result: not sent”;

break;

}

[self dismissModalViewControllerAnimated:YES];

}

#pragma mark –

#pragma mark Workaround

// Launches the Mail application on the device.

-(void)launchMailAppOnDevice

{

NSString *recipients = @”mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!”;

NSString *body = @”&body=It is raining in sunny California!”;

 

NSString *email = [NSString stringWithFormat:@”%@%@”, recipients, body];

email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];

}

#pragma mark –

#pragma mark Unload views

 

– (void)viewDidUnload

{

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

self.message = nil;

}

#pragma mark –

#pragma mark Memory management

– (void)dealloc

{

[message release];

[super dealloc];

}

for more detail Grab the Code From Here

How to Integrate iAd in your Application?


Hi,

Today I am going to discuss how apple iAd is integrated in our iPhone/iPad Native Application.It’s really a very simple task.I am dividing this task in 3 simple steps.

Step 1:

1.import iAd Framework to the Application.

2.Provide #import <iAd/iAd.h> in the particular controller where you want to show your Add.

3.Provide it’s delegate UIViewController <ADBannerViewDelegate>

4.Provide one  view to that particular ViewController.Assume I have taken

@property (weak, nonatomic) IBOutlet UIView *contentView;

Step 2:

Allocate it in ViewDidLoad method

– (void)viewDidLoad
{
_bannerView = [[ADBannerView alloc] init];
_bannerView.delegate = self;

[super viewDidLoad];
[self.view addSubview:_bannerView];
}

step 3:

Provides it’s delegate methods which i have mention bellowed.

– (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self layoutAnimated:duration > 0.0];
}

– (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[self layoutAnimated:YES];
}

– (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[self layoutAnimated:YES];
}

– (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{

return YES;
}

– (void)bannerViewActionDidFinish:(ADBannerView *)banner
{

}
– (void)layoutAnimated:(BOOL)animated
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
self.contentView.frame = contentFrame;
[self.contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}];
}

and your Advertisement is ready.

You can take the source code from Here.

(In File Option click on Download Original)