Several new types:
Http://blog.chinaunix.net/u3/104182/showart_2248115.html
1. Target-action mode
NSObject performselector: @selector () ... Similar to the use of function pointers. But it has limited transmission parameters. It is possible to use protocol substitution and can increase code clarity.
It has a waituntildone parameter that can be set to execute the method asynchronously or synchronously.
Use the function pointer to get great dynamics, but the cost is that the compiler does not know which method we are going to execute, so we do not find the error at compile time, only know the function pointer is correct when executing.
Target-action Paradigm is a completely object-oriented event-passing mechanism. At run time, the implementation is checked by the Respondstoselector: method. If there is an implementation, then use Performselector:withobject: to invoke the specific action.
2. Notification is a lightweight mechanism for communication between objects.
[[Nsnotificationcenter Defaultcenter] addobserver ...]; Register or subscribe to a message that can subscribe to a custom or system message.
[[Nsnotificationcenter Defaultcenter] postnotificationname ...]; Send Sync Message
System messages such as: uiapplicationwillterminatenotification
The message response function uses nsnotification as an argument.
Register multiple times for the same message, the message is sent more than once.
3. Protocal protocol, similar to the use of interfaces.
4. @select ()
In Objective-c, the name of the method contains the method name and the colon of the first parameter, along with the corresponding colon for all subsequent parameters, without a colon if there are no arguments.
-(void) foo: (ID) Bar WITHFOO1: (ID) bar1
{
}
The real name of this method is foo:withfoo1:
Instead of using the concept of function invocation in 5.Objective C, instead of "message" passing (messaging) between objects.
OBJC is a message mechanism to work with. Statements such as-(void) foo: (int) A are replaced at compile time by Objc_msgsend (Receiver,selector,arg1,arg2,....), in which case the code that sends the message is essentially the calling function (call function) , but they call the same function objc_msgsend, or Objc_msgsend_stret (the return value is a struct), Objc_msgsend_fpret (The return value is a floating-point type), and so on.
The parameters of the analysis Objc_msgsend (Receiver,selector,arg1,arg2,....), the type of the first receiver is the ID, the object that accepts the message, the second is the method that the selector represents the receiving object, followed by the parameter of the method . [Theclass Foo:10] is compiled into objc_msg (Theclass, @selector (foo:), 10);
Its implementation is based on OBJC runtime. The NSObject class implements this set of mechanisms, so each class that inherits from NSObject automatically gets runtime support. In such a class, there is an Isa pointer to the data structure body defined by the class, which is created by the compiler at compile time for the class (which must inherit from NSObject). In this structure, there are pointers to the definition of its parent class and dispatch table. The Dispatch table is a counterpart of the SEL and Imp. For a method with the same name, they all have the same SEL, the name of the method does not include the class name, so the method with the same name in the subclass and the parent class has the same SEL, but their implementations can vary, so that the imp corresponding to the SEL in their respective dispatch table is different. IMP is a function pointer, and although each SEL corresponds to the name of a method, given the efficiency, the SEL itself is an integral type, and the compiler generates a separate table for the SEL and the method name. With such a structure, OBJC can be implemented polymorphic.
6. Dynamically add messages to the class.
7.
Delegate:
The sender of the message (sender) informs the receiver (receiver) that an event is about to occur, delegate agrees and then the sender responds to the event, and the delegate mechanism allows the receiver to change the sender's behavior. Usually the relationship between the sender and the receiver is direct to a one-to-many relationship.
Notification:
The sender of the message informs the recipient that the event has occurred or is about to be sent, and that, in this case, the receiver does not affect the sender's behavior in turn. Usually the relationship between the sender and the receiver is an indirect many-to-many relationship.
Notification is broadcast.
Delegate is a point to point.
9.NSInvocation
10. The cooperation between the modules, as far as possible not to use Target-action mode, cautious use of notice, priority to use agents.
11.kvo=keyvalue Observing,kvc=key Value Coding
KVO is an important mechanism for cocoa, and he provides a way to observe the changes in a property, greatly simplifying the code. This observation-the observed model applies to situations where, for example, an attribute in B (view class) changes according to a property value of a (data Class). For cocoa, where MVC is admired, KVO is widely used. (Such a mechanism sounds like notification, but notification requires an object to send notification, usually notificationcenter, to inform the observer.) And KVO is the direct notification to the observation object. )
Http://www.cnblogs.com/scorpiozj/archive/2011/03/14/1983643.html
Cases:
Student *stu = [[Student alloc]init];
[Stu addobserver:self forkeypath:@ ' name ' Options:nskeyvalueobservingoptionold | Nskeyvalueobservingoptionnew Context:nil];
Stu.name = @ "John";
When the Stu.name value changes, the following method is called
-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: (nsdictionary *) Change context: (void *) Context
{
NSLog (@ "keypath:%@ object:%@ change:%@", Keypath,object,change);
}
Http://hi.baidu.com/492437598/blog/item/6ed35079c748e7f52f73b380.html
12. Call between applications
http://blog.csdn.net/pjk1129/article/details/6641211
http://blog.csdn.net/pjk1129/article/details/6643411
Jump to App Store:
[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "itms://itunes.apple.com/app/sandman/id388887746 ? mt=8&uo=4 "]];
Or
[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "itms-apps://itunes.apple.com/app/sandman/ Id388887746?mt=8&uo=4 "]];
[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "itms-apps://itunes.apple.com/app/ Hainan-tianya-online-network/id451916383?mt=8&uo=4 "]];
The latter opens the App Store directly
When the link in the page on the phone has http://itunes.apple.com/app ... , you need to replace HTTP with Itms-apps, and then jump to the App Store using the above method.
Jump to Rating:
Add the scoring button in the application, click to jump directly to the App store scoring interface, you can solve the user with a good software after forget or trouble, and do not go to the App Store scoring rating.
The link address of the App Store comment is itms-apps://ax.itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?type=purple +software&id = AppleID
nsstring* appleid=@ "451916383";
NSString *str = [NSString stringWithFormat:
@ "itms-apps://ax.itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?type=purple+software& id=%@ ",
AppleID];
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];
Add links to evaluation pages in iOS or Mac programs
http://blog.csdn.net/terrytan18/article/details/7377836
13. Open documents under Documents, or resource files in packages.
Open Word in a browser
NSString *path = @ "/..../xx.doc";
Nsurl *url = [Nsurl Fileurlwithpath:path];
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
[WebView Loadrequest:request];
Open solutions for other Access applications in the SDK
http://blog.csdn.net/arthurchenjs/article/details/6920631
Inter-application communication-URL Scheme
http://blog.csdn.net/flower4wine/article/details/6454957
Registering a custom URL Scheme in Mac and iOS
http://cocoa.venj.me/blog/custom-url-scheme-on-mac-and-ios/
Url-scheme to open some other applications in iOS applications
http://willonboy.tk/?p=742
iphone Development Tips URL scheme START process Debugging tutorial
Http://mobile.51cto.com/iphone-278973.htm
How do I call Safari in the program to open the local HTML file. There is no answer.
Http://www.cocoachina.com/bbs/read.php?tid=17135&page=1
13.1 Uidocumentinteractioncontroller with a real machine test, the simulator may not work.
Uidocumentinteractioncontroller uses Qlpreviewcontroller to display. It allows for additional hooks for delegate methods.
#pragma mark-
#pragma Mark Loaddocument.
-(void) Loaddocument: (nsstring*) path
{
/*
Use UIWebView
Nsurl *url = [Nsurl Fileurlwithpath:path];
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
if (!iwebview)
{
Iwebview=[[uiwebview alloc] initWithFrame:self.view.bounds];
Iwebview.scalespagetofit = YES;
For (ID subview in iwebview.subviews)
{
if ([[Subview class] Issubclassofclass: [Uiscrollview class]])
{
((Uiscrollview *) subview). bounces = NO;
}
}
[Self.view Addsubview:iwebview];
}
[Iwebview Loadrequest:request];
*/
Use Uidocumentinteractioncontroller
Nsurl *url = [Nsurl Fileurlwithpath:path];
uidocumentinteractioncontroller* controller = [[Uidocumentinteractioncontroller Interactioncontrollerwithurl:url] Retain];
Controller.delegate = self;
BOOL ret = [Controller Presentopeninmenufromrect:cgrectzero inView:self.view animated:yes];// Documentinteractioncontrollerdiddismissopeninmenu
if (!ret)
{
RET = [Controller Presentpreviewanimated:yes];//documentinteractioncontrollerdidendpreview
if (!ret)
{
[Dialogutil postalertwithmessage:@ "Open failed"];
}
}
}
#pragma mark-
#pragma Mark Uidocumentinteractioncontrollerdelegate.
-(Uiviewcontroller *) Documentinteractioncontrollerviewcontrollerforpreview: (Uidocumentinteractioncontroller *) Controller
{
return self;
}
-(void) Documentinteractioncontrollerdidendpreview: (Uidocumentinteractioncontroller *) controller
{
NSLog (@ "Documentinteractioncontrollerdidendpreview");
[Controller autorelease];
}
-(void) Documentinteractioncontrollerdiddismissopeninmenu: (Uidocumentinteractioncontroller *) controller
{
NSLog (@ "Documentinteractioncontrollerdiddismissopeninmenu");
[Controller autorelease];
}
13.2 The result is that the local file cannot be opened with Canopenurl
Nsurl *url = [Nsurl fileurlwithpath:[nsstring stringwithformat:@ "%@", Path]];
BOOL ret=[[uiapplication sharedapplication] canopenurl:url];
if (ret)
{
Ret=[[uiapplication sharedapplication] Openurl:url];
NSLog (@ "Canopenurl");
if (!ret)
{
[Dialogutil postalertwithmessage:[nsstring stringwithformat:@ "Open%@ failed", [url absolutestring]]];
}
}
Else
{
[Dialogutil postalertwithmessage:[nsstring stringwithformat:@ "can ' t open%@", [url absolutestring]]];
}
13.3 Draw PDFs using Qurtz's cgpdfdocumentgetpage,cgcontextdrawpdfpage and other related APIs.
13.4 on the iphone look at Word, Excel, pdf full Raiders
Http://iphone.tgbus.com/tutorial/use/200801/20080102113010.shtml
Use Qlpreviewcontroller to preview files in 13.5 iOS
http://www.acwind.net/blog/?p=1267
Quicklook.framework
#import <QuickLook/QLPreviewController.h>
if ([Qlpreviewcontroller canpreviewitem: (ID <QLPreviewItem>) Localfileurl])
{
qlpreviewcontroller* Previewcontroller=[[qlpreviewcontroller alloc] init];
previewcontroller.datasource=self;
[Viewcontroller Presentmodalviewcontroller:previewcontroller Animated:yes];
[Previewcontroller release];
}
#pragma mark-
#pragma Mark Qlpreviewcontrollerdatasource.
-(Nsinteger) Numberofpreviewitemsinpreviewcontroller: (Qlpreviewcontroller *) controller;
{
return 1;
}
-(ID) Previewcontroller: (Qlpreviewcontroller *) Previewcontroller Previewitematindex: (nsinteger) IDX
{
nsurl* Url=previewitemurl_;
return URL;
}
14.http://tiny4cocoa.com/thread-1963-1-1.html
There are 2 of messages in iOS that can call an object directly
One is performselector:withobject:
And one is nsinvocation.
The first approach is simpler and can be done simply by calling. However, for >2 parameters or the processing of return values, there is a need for additional work to be done. So in this case, we can use nsinvocation to do these relatively complex operations
Nsinvocation can handle parameters, return values. Java people know that all operations, in fact, nsinvocation is equivalent to reflection operation.