NSURLConnection allows for controlled from a connection to a remote server. To use it simply:
1 2 3 4 5 6 7 8 9 10 11
| / / The objects sufficient to perform a NSURLConnection urlConnection; NSURLConnection * URLConnection; mutableData; NSMutableData mutableData *; / / ... urlString = @ "http://www.miodominio.com/documento.txt" ; NSString * urlString @ = "http://www.miodominio.com/documento.txt"; urlRequest = [ NSURLRequest requestWithURL : [ NSURL URLWithString : urlString ] ] ; NSURLRequest URLRequest = * [ NSURLRequest requestWithURL: [ NSURL URLWithString: urlString]]; / / The delegate will respond to the states of the connection NSURLConnection alloc ] initWithRequest : urlRequest delegate : self ] ; URLConnection = [[ NSURLConnection alloc] initWithRequest: URLRequest delegate: self]; |
Here are delegate methods to check the status of the connection:
[Cc_objc]
Continued ...
Objective-C is a wonderful language that allows you to do amazing things. One of the most interesting aspects is its dynamic invocation of methods (messages). You can, in fact, get the address of a message from a string.
Continued ...
The object UIWebView can be used to display several files. For example you can use it to display - as well as QuickTime movies or YouTube - PDF or HTML file included in our code.
Continued ...
NSString is a powerful class, let me show you some of the most used properties:
printf ()
1 2
| / / Printf () output = [ NSString stringWithFormat : @ "%@ / %@" , @ "primo" , @ "secondo" ] ; NSString * output = [ NSString stringWithFormat: @ "% @ /% @", @ "first", @ "second"]; |
Run the split ()
1 2 3
| / / Split () / explode () list = @ "Norman, Stanley, Fletcher" ; NSString * list = @ "Norman Stanley Fletcher"; listItems = [ list componentsSeparatedByString : @ ", " ] ; NSArray * ListItems = [list componentsSeparatedByString: @ ""]; |
Convert from string to value
1 2 3
| / / Converting doubleString = @ "123" ; NSString * @ doubleString = "123"; [ doubleString doubleValue ] ; double value = [doubleString doubleValue]; |
Within a string
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| / / Substring searchString = @ "age" ; NSString * @ searchString = 'age'; beginsTest = @ "Agencies" ; NSString * beginsTest @ = "Agencies"; [ beginsTest rangeOfString : searchString NSRange prefixRange = [beginsTest rangeOfString: searchString NSAnchoredSearch | NSCaseInsensitiveSearch ) ] ; options: (NSAnchoredSearch | NSCaseInsensitiveSearch)]; / / PrefixRange = {0, 3} endsTest = @ "BRICOLAGE" ; NSString * endsTest = @ "DIY"; [ endsTest rangeOfString : searchString NSRange suffixRange = [endsTest rangeOfString: searchString NSAnchoredSearch | NSCaseInsensitiveSearch | NSBackwardsSearch ) ] ; options: (NSAnchoredSearch | NSCaseInsensitiveSearch | NSBackwardsSearch)]; / / SuffixRange = {6, 3} |
Continued ...
To compose mail in an application iPhone / iPod, simply add the framework MessageUI . In our controller to enter the inclusion of the framework and adopt the Protocolo MFMailComposeViewControllerDelegate :
Continued ...
davanti al prototipo, tipo: When you define and use methods (messages) under Objective-C, we are often faced with the curious syntax that shows a sign - or + in front of the prototype, type:
1 2 3 4 5 6 7
| / / In the definition void ) mioMessaggio; - (Void) mioMessaggio;
/ / Similarly, in the implementation void ) mioMessaggio { - (Void) {mioMessaggio / / ... } |
Or:
1 2 3 4 5 6 7
| / / In the definition void ) mioMessaggio; + (Void) mioMessaggio;
/ / Similarly, in the implementation void ) mioMessaggio { + (Void) {mioMessaggio / / ... } |
The difference is that the methods defined by the symbol - are instance methods, then linked to an object. The methods defined by the symbol + are called class methods, as they can be performed without allocating and instantiate the object in question.
sono due classi, molto usate, che contengono svariati metodi di classe. NSString or UIView are two classes, widely used, which contain several class methods. Class methods are used continuously, as when we initialize or allocate any object:
1
| [ UIView alloc ] ; MyView UIView * = [UIView alloc]; |
The method alloc is a classic example, present in all objects and, as is evident from the code, a class method is invoked as before allocation of the object itself.
Class methods can be useful in many cases, particularly when we create our object and we want to allocate and initialize it in less lines of code as possible. Imagine having to collect a number in an array of objects defined by us. We define our object, first of all, writing the code in the simplest way, without using class methods:
1 2 3 4 5 6 7 8 9 10
| / / Define the interface myObject.h # Import <Foundation/Foundation.h> NSObject { @ Interface myObject: NSObject { name; NSString * name; lastname; NSString * lastname; } nonatomic, retain ) NSString * name; @ Property (nonatomic, retain) NSString * name; nonatomic, retain ) NSString * lastname; @ Property (nonatomic, retain) NSString * lastname; |
The implementation, in the simplest case, nothing could be either:
1 2 3 4 5 6 7 8 9 10 11 12
| / / MyObject.m
# Import "myObject.h" @ Implementation myObject
@ Synthesize name, lastname;
void ) dealloc { - (Void) dealloc { ; [Name release]; ; [Lastname release]; ; [Super dealloc]; } |
When we get to use our object, we will use a code like this:
1 2 3
| [ myObject alloc ] ; myObject * obj = [myObject alloc]; "Mario" ; obj.name @ = "John"; "Rossi" ; obj.lastname @ = "Smith"; |
If we wanted to create many objects of this type, and place them in an NSArray , the situation becomes a little awkward:
1 2 3 4 5 6 7 8 9 10 11 12
| [ myObject alloc ] ; objA * myObject = [myObject alloc]; "Mario" ; objA.name @ = "John"; "Rossi" ; objA.lastname @ = "Smith"; [ myObject alloc ] ; objB * myObject = [myObject alloc]; "Carlo" ; objB.name @ = "Charles"; "Bianchi" ; objB.lastname @ = "Smith"; elenco = [ NSArray arrayWithObjects : objA, objB, nil ] ; NSArray * list = [ NSArray arrayWithObjects: objA, objB, nil]; ; [ObjA release]; ; [ObjB release]; |
per aggiungere man mano gli oggetti nel nostro elenco. You could improve the code by creating a loop for or using an NSMutableArray to add as objects in our directory. . However, the situation of migliorebbe little, when they would remain outside the property settings name and lastname . Would then be spontaneous, to start, add a method - object - initWithName that would allow you to jump to the property settings, simplifying things a bit. In the implementation file myObject.m add:
1 2 3 4 5 6 7
| id ) initWithName : ( NSString * ) stringName lastname : ( NSString * ) stringLastname { - (Id) initWithName: ( NSString *) StringName lastname: ( NSString *) {stringLastname self = [ super init ] ) { if (self = [super init]) { self.name = StringName; self.lastname = stringLastname; } return self; } |
In doing so we have improved the situation, they can now write:
1 2 3 4 5 6 7
| [ [ myObject alloc ] initWithName : @ "Mario" lastname : @ "Rossi" ] ; objA * myObject = [[myObject alloc] initWithName: @ "John" lastname: @ "Smith"]; [ [ myObject alloc ] initWithName : @ "Carlo" lastname : @ "Bianchi" ] ; objB * myObject = [[myObject alloc] initWithName: @ "Charles" lastname: @ "Smith"]; elenco = [ NSArray arrayWithObjects : objA, objB, nil ] ; NSArray * list = [ NSArray arrayWithObjects: objA, objB, nil]; ; [ObjA release]; ; [ObjB release]; |
, necessari per l'inserimento nell'array e liberare la memoria. Yet still have pointers objA and objB , necessary for the entry in the array and free memory. Wishing we could be entered directly in the creation of an object populating the array, using autorelease to free up memory, but the code would still not idle. Let me demonstrate how to solve the issue with a class method. First of all we replace - (id)initWidthName with:
1 2 3 4 5 6 7 8 9 10
| id ) initWithName : ( NSString * ) name lastname : ( NSString * ) lastname { + (Id) initWithName: ( NSString *) name lastname: ( NSString *) {lastname myObject * item; item = [ [ self alloc ] init ] ) { if (item = [[self alloc] init]) { / / Init item.name = name; item.lastname = lastname; } item autorelease ] ; return [item autorelease]; } |
In doing so we created a class method that allocates (in autorelase) and actually initiated one of our object, first you have the pointer to the instance. The code used is then:
1 2 3 4
| elenco = [ NSArray arrayWithObjects : NSArray * list = [ NSArray arrayWithObjects: @ "Mario" lastname : @ "Rossi" ] , [MyObject initWithName: @ "John" lastname: @ "Smith"], @ "Carlo" lastname : @ "Bianchi" ] , [MyObject initWithName: @ "Charles" lastname: @ "Smith"], ; nil]; |
Much, much better ...
Continued ...
Apple iPhone and iPod were used to manage a single image file to load the application, the file Default.png . Apple iPad, however, the different management orientation requires the use of multiple image files, to be sure you see the splash screen correctly based on the orientation of the device. During application startup, as was the case for the iPhone, it is not possible to intervene to code for "wonder" as the device-oriented. Fortunately it was introduced in automatic loading of special files depending on the orientation:

The files are currently supported, in addition to the classic Default.png do not recommend to use because it is scaled and deformed according to guidance, are:
- Default-Portrait.png
- Default-PortraitUpsideDown.png
- Default-Landscape.png
- Default-LandscapeLeft.png
- Default-LandscapeRight.png
e LandscapeRight possono essere utilizzate per determinare orietamento e verso di quest'ultimo. Versions PortraitUpsideDown , LandscapeLeft and LandscapeRight can be used to determine orietamento and toward the latter.
Application to start, then, as recommended by Apple, it's good "redesign" - where necessary - our views acting within application:didFinishLaunchingWithOptions .
Continued ...
With the release of WordPress 3.0 will change many things for us developers. Updates to this major release are many and very useful for those developing with this CMS now truly complete. We could say that if you close one era and opens a new and full of possibilities. I pay tribute to the then previous versions with a range of useful snippets some very valid even with the new release.
Continued ...
Let me show you how to implement a simple Slideshow of images with very few lines of code, using jQuery .
This technique can be implemented on any type of website, the important thing is to include the library jQuery . I used this technique to a site built in WordPress , developed in a few hours for an event.
Continued ...
Sometimes it can be useful to include in a page the contents of another. For example if you have created a registration page and volote show in a box of privacy disclosures, it would be handy to be able to upload this content to an existing page. This has the advantage:
- The customer can change the page content without "tocccare" the original page that contains
- The page works well alone, so you can put in the footer of the site a link to "privacy" for example
The best way to include the contents of one or more pages is as follows:
1 2 3
| get_page_by_title ( "Privacy" ) -> ID ; Postid = $ get_page_by_title ("Policy") -> ID; get_post ( & $postID ) ; $ Post = get_post (& $ postid); "the_content" , $post -> post_content ) ; echo apply_filters ('the_content', $ post -> post_content); |
The ID of the post (the page in the example above) is obtained by its title both for clarity and for compatibility with export or re-index involuntary.
Continued ...
Latest Comments
Robert : I rispsoto your questions with pleasure. The idea is really great. I am looking for a solution ...
Sting : @ Darius - you can see an example here: http://www.fight4fun.it/ clicking on: MAPS I hope ...
vik : Giustappunto I'm working on a project and the client asked me to show all the news (which are CPT) in ...
Giovambattista Fazioli : @ paso: absolutely. Simply identifying the field [cci] input [/ cci] you want to ...
paso : Hello I would like to request a service, you can use the datepicker with cform7 I spiegp best I can implement ...