Wednesday 31 October 2012

How to check Device is iphone 4 or iphone 5

  float height = [UIScreen mainScreen].bounds.size.height;
   
    if (height==568) {
        self.deviceType = 5;
    }
    else
    {
        self.deviceType = 4;
    }

Tuesday 11 September 2012

How to use uiview in subviews in iphone sdk

for (UITextField *txt in ViewPost.subviews)
    {
        if ([txt isKindOfClass:[UITextField class]])
        {
            if (txt.tag==index)
            {
                txt.text = appDelegate.answerDynamic;
                [appDelegate.arrAnswer addObject:appDelegate.answerDynamic];
                NSLog(@"%@",appDelegate.arrAnswer);
            }
        }

    }

Sunday 1 July 2012

How to make splash screen animation in iphone sdk

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
   
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
    }
    else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {         
        if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
        {
            _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Landscape.png"]];           
        }
        else
        {
            _animationBookCoverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Portrait.png"]];
        }
    }
   
    // Offset by the status bar on iPad. We don't on iPhone because splashscreens take up the full height.
    // No idea why Apple did this differently for iPhone and iPad.
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        _animationBookCoverView.frame = CGRectMake(0, 20,
                                                   _animationBookCoverView.frame.size.width,
                                                   _animationBookCoverView.frame.size.height);
    }
   
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    self.view.backgroundColor = [UIColor clearColor];
    _animationBookCoverView.backgroundColor = [UIColor clearColor];
   
    [self.view addSubview:_animationBookCoverView];
   
    // Credit to this smart cookie:
    // http://mo7amedfouad.com/2011/12/book-cover-flip-animation-like-in-path-app/
   
    _animationBookCoverView.layer.anchorPoint = CGPointMake(0, .5);
    _animationBookCoverView.center = CGPointMake(_animationBookCoverView.center.x - _animationBookCoverView.bounds.size.width/2.0f, _animationBookCoverView.center.y);
    [UIView beginAnimations:@"openBook" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView setAnimationDuration:3.0];
    [UIView setAnimationDelay:0];
    CATransform3D _3Dt = CATransform3DIdentity;
    _3Dt = CATransform3DMakeRotation(M_PI/2.0, 0.0f, -1.0f, 0.0f);
    _3Dt.m34 = 0.001f; // Perspective
   
    _animationBookCoverView.layer.transform = _3Dt;
    [UIView commitAnimations];
   
    // Super hack. Adding a view to the window in Landscape on an iPad just doesn't work.
    // Used this guy's approach to manually rotate it:
    // http://stackoverflow.com/questions/1484799/only-first-uiview-added-view-addsubview-shows-correct-orientation/2694563#2694563
    // And then I learned that LandscapeLeft and PortraitUpsideDown need to be rotated an extra 180
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        CGAffineTransform rotate;
       
        if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            rotate = CGAffineTransformMakeRotation(M_PI/2.0);
        }
        else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        {
            rotate = CGAffineTransformMakeRotation(M_PI);
        }
        else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            rotate = CGAffineTransformMakeRotation(1.5 * M_PI);
        }
        else
        {
            // UIInterfaceOrientationPortrait - Only one that works without hacks
            return;
        }
       
        [self.view setTransform:rotate];
        self.view.frame = CGRectMake(0, 0, 1024, 768);
    }
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag context:(void *)context
{
    [self.view removeFromSuperview];
}

Wednesday 20 June 2012

diffrent iphone demos for learning......20-6

http://iphone-example.blogspot.in/

//////////////////////////////////////////////////////////////

http://www.icodeblog.com/

//////////////////////////////////////////////////////////////////

http://goaheadwithiphonetech.blogspot.in/

/////////////////////////////////////////////////////

http://ilarump.blogspot.in/

////////////////////////////////////////////////

http://maheshbabuiphonedeveloper.blogspot.in/

For learning iphone programming for diffrent demos

http://ranga-iphone-developer.blogspot.in/

http://ved-dimensions.blogspot.in/

http://beginnersiosdev.blogspot.in/

For learn Iphone Programming...

http://iphone-ipad-code.blogspot.in/2012/05/how-text-length-of-uitextview-can-be.html

http://vijaysinghadhikari.blogspot.in

http://iphonebyradix.blogspot.in/

how text length of a UITextView can be fixed in iphone sdk?

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSUInteger newLength = (text_View.text.length - range.length) + text.length;
    if(newLength <= 140)
    {
        return YES;
    } else {
        NSUInteger emptySpace = 140 - (text_View.text.length - range.length);
        textView.text = [[[textView.text substringToIndex:range.location
                          stringByAppendingString:[text substringToIndex:emptySpace]]
                         stringByAppendingString:[textView.text substringFromIndex:(range.location + range.length)]];
        return NO;
    }
}

Basic Concept of Objective C and Iphone sdk



Objective C Concepts with iPhone




Little about objective C:


Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s at their company Stepstone
Its implementation of an object-oriented extension to the C language. 
Objective-C derives its object syntax from Smalltalk.







What is Class?
Ans.  In Objective-C, we define objects by defining their class. The class definition is a prototype for a kind of object; it declare the instance variable that become part of every member of the class, and it defines a set of methods that can be use by all objects in a class.


What is Object?
Ans. As the name implies that object orient programme based around object. The object associate data with particular operation that that affect or use data.

What is difference between function calls and messages?
 Ans. A function and its argument are joined together at compile time, but a message and a receiving object are united until the programme is running and message is sent.

What is polymorphism?
Ans.  It mean having multiple form. 
  • Polymorphism is the ability to process objects differently depending on their data types.
  • Polymorphism is the ability to redefine methods for derived classes.
There is two types of polymorphism in OOPS:
  1. Compile time
  2. Run Time.
Compile Time: Method overloading, means two same name methods with different argument.

Run Time: Method overriding, means same name, same signature but different implementation.
What is Inheritance?
Ans. Inheritance is a way to reuse of existing code or code of existing objects.
What is NSObject Class?
Ans. NSObjects is root class, that doesn't have any superclass. Its define basic framework of Objective-C and its Objects interaction.
What is Abstract Class?
Ans. Abstract class is a incomplete class, but contains the useful code that reduce the burden of its subclass.

What is Interface and its implementation?
Ans.
  • An interface that declares the methods and instance variables of the class and names its superclass
  • An implementation that actually defines the class (contains the code that implements its methods)


    A typical interface and its implementation:
    _____________________________________
    @interface rectangle: Superclass{


    instance variables declaration only....
    .........
    .......
    ........

     }
    method declaration only

    @end


    ______________________________________
    #import "rectangle.h"


    @implementation rectangle
    @synthesize the variable for getter-setter methods


    method definitions


    @end
    _______________________________________

Scope of instance variable in objective c
Some important delegates in iPhone Xcode:
UITableViewDelegate:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView ;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;





CLLocationManage Delegate:


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;

MKMapView Delegate

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation;

-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control ; 


UIWebView Delegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

- (void)webViewDidStartLoad:(UIWebView *)webView;

- (void)webViewDidFinishLoad:(UIWebView *)webView;


UISearchBar Delegate
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchB ;

- (void)searchBar:(UISearchBar *)searchB textDidChange:(NSString *)searchText ;

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchB ;

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchB;



UIActionSheet Delegate and UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex ;



MFMailComposeViewControllerDelegate with code:

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayMailComposerSheet 
{
   MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease]; 
    picker.mailComposeDelegate = self;
   if([MFMailComposeViewController canSendMail])
     {
      [picker setSubject:@"Near2Me iPhone App Feedback"];
       NSString *emailBody =@"";
       [picker setToRecipients:[NSArray arrayWithObjects:@"xyz444&6@gmail.com",nil]];
       [picker setMessageBody:emailBody isHTML:NO];
       [self.homeView presentModalViewController:picker animated:YES];
       }
}


// 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 
{
// Notifies users about errors associated with the interface
switch (result)
    {
     case MFMailComposeResultCancelled:
     NSLog(@"Result: canceled");
     break;
    case MFMailComposeResultSaved:
    NSLog(@"Result: Saved");
    break;
    case MFMailComposeResultSent:
           if (MFMailComposeResultSent)
           {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Near2Me Team"
             message:@"Thanks for your feedback. We always try to make application more simpler and            accurate."
            delegate:nil 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil];
           [alert show];
           [alert release];
            }
    NSLog(@"Result: Sent");
   break;
   case MFMailComposeResultFailed:
   NSLog(@"Result: failed");
   break;
   default:
   NSLog(@"Result: not Send");
   break;
   }
[self.homeView dismissModalViewControllerAnimated:YES];
//[appDeleg.window addSubview:appDeleg.viewMenuTab];
}







UINavigationController
homeView = [[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:[NSBundle mainBundle]];


navigation = [[UINavigationController alloc]initWithRootViewController:homeView];

[self.window setBackgroundColor:BGCOLOR];

[self.window addSubview:navigation.view];





// hiding - show navigationController setToolbar

    [self.navigationController setToolbarHidden:YES animated:NO];








UITabBarController



 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];

UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];

tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

self.window.rootViewController = self.tabBarController;










NSXMLParser


Parsing the start of an element
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict ;


Parsing an element’s value

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

Parsing the end of an element//XMLParser.m
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {






UIPickerView Delegates


- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
 
return [arrayColors count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrayColors objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
 
NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row);
}