Translate

Tuesday, March 19, 2013

Basic Concept of Objective C and Iphone sdk


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 = [[[MFMailComposeViewControllerallocinitautorelease]; 
    picker.mailComposeDelegate = self;
   if([MFMailComposeViewController canSendMail])
     {
      [picker setSubject:@"Near2Me iPhone App Feedback"];
       NSString *emailBody =@"";
       [picker setToRecipients:[NSArrayarrayWithObjects:@"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 allocinitWithFrame:[[UIScreen mainScreenbounds]]autorelease];
UIViewController *viewController1 = [[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nilautorelease];

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

tabBarController = [[[UITabBarController allocinitautorelease];
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);
}

No comments:

Post a Comment