Although I have long known three20 as a powerful library, I have never learned how to use it. I personally think that one of the best ways to learn is to take notes, so as to facilitate the future, and to make people "pick a thorn" to achieve the purpose of communication. Finally, I hope that through the blog platform, I can monitor my learning process.
20110517
When learning, I first paid attention to the category of the cocoa class in ttcore (I saw the core, so I started from this. For example, nsstring can be used to determine the line feed of spaces, parse URL requests, and generate MD5. There is also nsdate, which has a lot of practical methods to format the time output string. These category categories are easy to understand, and the effect can be easily seen by name during use. Among these methods, there is a strange function. I will write the comments below.
Performselector:
- ( ID ) Performselector :( SEL) selector withobject :( ID ) P1 withobject :( ID ) P2 withobject :( ID ) P3 {
Nsmethodsignature * SIG = [Self methodsignatureforselector: Selector];
// Record the parameter and return value types of the method, which are usually used to transmit messages between objects. Generally, an nsinvocation object is created to call the method.
If (SIG ){
Nsinvocation * Invo = [Nsinvocation invocationwithmethodsignature: SIG]; // Storage and transmission of Inter-Object Information
[Invo settarget: Self];
[Invo setselector: Selector];
[Invo setargument: & P1 atindex: 2 ]; // Note the index number
[Invo setargument: & P2 atindex: 3 ];
[Invo setargument: & P3 atindex: 4 ];
[Invo invoke]; // Call a function to determine whether a return value exists.
If (SIG. methodreturnlength ){
ID Anobject;
[Invo getreturnvalue: & Anobject];
Return Anobject;
} Else {
Return Nil;
}
} Else {
Return Nil;
}
}
Most of iOS users need to deal with navigationcontroller, tabbarcontroller, and tableviewcontroller. You have to see how three20 operates. Before that, we need to understand the URL-based navigator. Ttnavigator refers to the class in the form of a URL string through map to hide the response. When you need a class, you only need to generate the URL of the load naviging rule.
ttnavigator * navigator = [ttnavigator navigator];
navigator. window = window;
tturlmap * Map = navigator. urlmap;
[map from: @ " TT: // restaurant/(initwithname :) "
toviewcontroller: [deleantcontroller class ];
To call the ingress antcontroller, you only need to generate a URL, for example:@ "TT: // restaurant/Chinese", you can call it.
[Navigator openurlaction: [tturlaction actionwithurlpath:@"Http://github.com/jverkoey"];
[[Ttnavigator navigator] openurlaction:
[[Tturlaction actionwithurlpath:@"TT: // restaurant/Chotchkie's"] Applyanimated: Yes]
Another huge advantage of ttnavigator is persistence. For example, if you disable tabbarcontrollerProgramPreviously on The tab3 page, you are still on the tab3 page when you open it again. When you use a URL, ttnavigator remembers the URL call stack. When you use it again, only the latest viewcontroller will be initialized. Because all URLs are recorded, you do not need to worry about how to back them if I need to go back to the upper-level page. Ttnavigator will be instantiated Based on the URL as needed, which greatly saves memory.
Next, let's take a look at how URLs are mapped to classes. First look at a ing:
[Map from:@"TT: // menu/(initwithmenu :)/(page :)"
Tosharedviewcontroller: [menucontrollerClass];
Then @ "TT: // menu/1/5" is equivalent to calling:
[[Menucontroller alloc] initwithmenu:1Page:5]
Tableviewcontroller in 320 is tttableviewcontroller, which has many outstanding features. One possible advantage is that many datasource and delegate implementations are saved.Code. It is easy to generate datasource, for example:
Self. datasource = [Ttsectioneddatasource performancewithobjects: @" A " ,
[Tttabletextitem itemwithtext: @" Alen " URL: @" TT: // mydetail/ " ],
[Tttabletextitem itemwithtext: @" Alva " URL: @" TT: // mydetail/B " ],
Nil];
// Ttlistdatasource, which can be used as needed
After learning about the above rules, we can basically write an example of navigationcontroller or tabbarcontroller (this trainer is familiar with URL writing rules first ).
- ( Void ) Applicationdidfinishlaunching :( uiapplication * ) Application
{
Ttnavigator * Navigator = [Ttnavigator navigator];
// Select persistence Mode
Navigator. persistencemode = Ttnavigatorpersistencemodeall;
Navigator. Window = [[[Uiwindow alloc] initwithframe: ttscreenbounds ()] autorelease];
Tturlmap * Map = Navigator. urlmap;
// Any URL that doesn' t match will fall back on this one, and open in the Web browser
[Map from: @" * " Toviewcontroller: [ttwebcontroller Class ];
// The tab bar controller is shared, meaning there will only ever be one created. Loading
// This URL will make the existing tab bar controller appear if it was not visible.
[Map from: @" TT: // tabbar " Tosharedviewcontroller: [mytabcontroller Class ];
[Map from: @" TT: // menu/(initwithmenu :) " Tosharedviewcontroller: [menucontroller Class ];
// [Map from: @ "TT: // Mymenu/(initwithnumber :) "tosharedviewcontroller: [menucontroller class];
[Map from: @" TT: // mydetail/(loadfromnib :) " Toviewcontroller: [mydetailviewcontroller Class ];
If ( ! [Navigator restoreviewcontrollers]) {
// This is the first launch, so we just start with the tab bar
[Navigator openurlaction: [tturlaction actionwithurlpath: @" TT: // tabbar " ];
}
}
Note that the original
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
Comment out because it seems that the priority of applicationdidfinishlaunching is not high.
For more information, see three20info.