…
Nel tutorial di oggi vi mostreremo come creare una semplice richiesta URL sincrona con Objective-C.
// Quick synchronous URL request NSURL *url = [NSURL URLWithString:@"http://some-internet-place"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLResponse *response; NSError *error; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; // need to check for errors, like if it was a bad call there will be no responsestring // but your error will have some data if(!error) { NSLog(@"response = %@", responseString); // Take all data …
In questo semplicissimo tutorial imparerete come creare un alert con Objective-C.
NSString *message = @"tuo messaggio"; UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:message delegate:self cancelButtonTitle:@"Chiudi" otherButtonTitles:nil, nil]; [alert show];
Per prima cosa abbiamo creato una variabile di tipo stringa che contiene il messaggio da mostrare. Successivamente abbiamo creato un alert view che prende come parametro il messaggio.…
…
Nel tutorial di oggi imparerete come passare una variabile da un sito web (php in questo caso) a una applicazione iOS.
//in iOS code NSData *dataFromURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.mywebsite.com/someProgramme.php"] options:NSDataReadingUncached error:&error]; if(error) { NSLog(@"%@", [error localizedDescription]); } else { NSLog(@"Data had loaded successfully"); } NSString *resultString = [[NSString alloc] initWithData:dataFromURL encoding:NSUTF8StringEncoding]; NSLog(@"result : %@", resultString); /* in php code as a very simple example < ?php - function someFunction () { $variable …
…
…
…
…
Nel tutorial di oggi imparerete come cambiare il colore del testo di un NSButton con Objective C.
- (void)setButtonTitleFor:(NSButton*)button toString:(NSString*)title withColor:(NSColor*)color { NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setAlignment:NSCenterTextAlignment]; NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys: color, NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName, nil]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary]; [button setAttributedTitle:attrString]; [style release]; [attrString release]; } …