Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Atomic
Nonatomic
Any implementation we add will override the synthesized version
Block Declaration declare as
Local Variable - <returnType> (^<blockName>) (<parameterType>) =
Property - @property (nonatomic, copy) int(^equation) (int, int);
Parameter of a method (void)setEquation: (int(^) (int, int))
blockName;
Argument of a method [simpleOP setEquation:^int(int a, int b)
{return a+b;}];
Typical Use: Enable the caller to provide the callback code at the point
of invocation. Use in system framework APIs (completion handlers,
notification handlers, error handlers, enumeration, view animation
and transitions, sorting)
Chapter 2
XIB file an XML representation of the achieved objects.
Chapter 3
View and the view hierarchy
-Make up the user interface of an application.
Drawing
-Drawing operations performed on the CGContextRef must fall within
the bounds rectangle. Otherwise, they will be clipped to that rectangle
Core Graphics framework
-A C language API for 2D drawing
-The hub of the Core Graphics framework is CGContextRef:
-(void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect bounds = [self bounds];
CGContextSetLineWidth(ctx, 10); -> set up drawing state
CGContectSetRGBStrokeColor(ctx, 1, 0, 0, 1); -> set color
CGContextAddRect(ctxm bounds); -> added a path to the context
CGContextStrokePath(ctx);
->
perform
drawing
operation
}
Motion Event Methods For handling shakes, the methods toy
override in a UIResponder subclass are known as the motion event
methods
When a UIViewController is instatiated, it doesnt create or load its
view right away. Only when the view is moving to the screen will a
view controller bother to create its view.
View will be destroyed if system is running low memory or is not
current view in the screen.
To Avoid Memory leaks, the convention for IBOutets is to declare them
as weak references. One exception of this rule: Keep a strong
reference to top-level objects in a XIB file.
Segue is the transition from one scene to another within a storyboard
[self performSegueWithIdentifier:@ sender:self];
[segue.destinationViewController
performSelector:@selector(setLabelText:) withObect:@arrive from 1
Chapter 4
UITableView a table view for displaying and editing hierarchical lists
of information. Use UITableViewCell objects to draw the visible rows of
the table. Is made up of zero or more sections, each with its own rows.
UITableViewController
numberOfRowsInsection,
numberOfSectionsInTableView,
cellForRowAtIndexPath
UITableViewCellStyles
Chapter 5
UIWebView
NSURL * url = [NSURL URLWithString:urlString];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[self.detailViewController.webView loadRequest:request];
Hide the keyboard
-(IBAction)textFieldReturn:(id)sender{
[sender resignFirstResponder];}
Chapter 6
NSErrpr *error;
[context save:&error];
Find Data
AppDelegate * appdelegate = [[UIApplication sharedAppication]
delegate];
NSManagedObjectedContext * context =
[appDelegate managedObjectContext];
NSEntityDescription * entityDesc = [NSEntityDescrption
entityForName:@Contacts inManagedObjectContext:context];
NSFetchRequest * request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSPredicate * pred = [NSPredicate predicateWithFormat:@(name
= %@), _name.text];
// LIKE %%;
[request setPredicate:pred];
NSError * error;
NSArray * objects = [context executeFetchRequest:request
error:&error];
If (object.count>0){
NSManagedObject *matches = _object[0];
}
Edit
NSFetchRequest * request = [[NSFetchRequest alloc] init];
[request setEntity: [NSEntityDescriotion entityForName:@Contatcs
inManagedbjectContext: context]];
NSError * error = nil;
NSArray * results = [context executeFetchRequest error:&error];
[context save:&error];
Delete
NSManagedObjectContext * context = [self.fetchResultsController
managedObjectContext];
NSManagedObjectContext * objectToBeDeleted = [self.
fetchResultsController objectAtIndexPath: indexPath];
[context deleteObjectLobjectToBeDeketed];
NSError = nil;
[context save:&error];
Photolot
-(void) addItemViewController: (AddViewController*)
controller(Photo*) item
{
Photo * op = [[Photo alloc] init];
op = item;
[_PhotoList insertObjectLop atIndex:[_PhotoList count]];
[_PhotoTable reloadData];
}
-(void)prepareForSegue: (UIStoryboardSegue*)segue sender:
(id)sender{
If ([[segue identifier] isEqualToString:@Detail])
{
DetailViewController * detailView = [segue
destinationCiewController];
NSIndexPath * myIndexPath = [selfTableView
indexPathForSelectedRow];
[detailView setOb:[_PhotoList objectAtIndex:tow];
} else if ([[segue identifier] isEqualToString:@NewPhoto]){
AddViewController * viewControllerB = [segue
destinationViewController];
viewControllerB.delegate = self;
}
}
-(void)tableView: (UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:
(NSIndexPath *)indexPath
{
If(editingStyle == UITableViewCellEditingStyleDelete){
_indexPath = indexPath;
UIAlertView *alertView =
[[UIAlertView alloc]initWithTitle:@"Confirm Delete" message:@"You
sure to delete ? " delegate:self cancelButtonTitle:@"Yes"
otherButtonTitles:@"No", nil];
[alertView show];
}
}
-(void)DeleteRow: (NSIndexPath*) indexPath
{
[_PhotoList removeObjectAtIndex:indexPath.row;
[_PhotoTable deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation: UITableViewRowAnimationAutomatic];
}
-(void)alertView: (UIAlertView*)alertView clickedButtonAtIndex:
(NSInteger) buttonIndex
{
If (buttonIndex == 0)
{ selfDeleteRowL_indexPath};
}
}
Map
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import <AddressBook/AddressBook.h>
CLLocationCoordinate2D coords;
-(IBAction)getDirections:(id)sender
{
CLGeocoder * geocoder = [[CLGeocoder alloc] init];
NSString * addressStr = [NSString stringWithFormat:@%@ %@ %@
%@, _address.text, _city.text, _state.text, _zip.text];