The first source that I went in his hands was written in Basic and consisted of a few lines of code, for enlightening me. It was a simple game that generated a random number from 1 to 10 and, through keyboard input, proved that the number entered was Maggione, less than or equal to the random number. Despite its rough simplicity remains, for me, one of the best examples - simple, fun and practical - to explain to those who do not know anything about programming what is meant actually for "computer program". So I decided to propose it for Apple iPhone, maybe will help someone ...
Articles Tagged 'Apple'
iPhone FirstApp: Guess the number - Part 1
Objective-C: type conversion
With some high-level languages such as JavaScript or PHP, where data are not typed or otherwise can not be, we are "spoiled" in compare or convert strings and integers and vice versa, all hidden or manipulated by the interpreter (or compiler ). For example in Javascript functions are "forced" (like parseInt() for example) required in special cases. However in other circumstances treat the integers without worry of particular conversions (explicit), such as:
1 2 3 | 5 ; mioNumero var = 5; / / ... "Il valore di mioNumero è " + mioNumero ) ; alert ("The value is mioNumero" mioNumero +); |
Objective-C, however, the data type is important and the type conversion must be express. Besides the casting (better typecasting) we can use the features and functionality specific to the type conversion. For example, here is how to convert an integer to a string:
1 2 3 4 |
In contrast, here is how to convert a string to an integer:
1 2 3 4 | miaStringa = @ "128" ; NSString * myString = @ "128"; [ miaStringa integerValue ] ; mioNumero int = [myString integerValue]; / / "miaStringa=%@ mioNumero=%i" , miaStringa, mioNumero ) ; NSLog (@ "% @ myString = mioNumero =% s", myString, mioNumero); |
iPhone code snippet: UIAlertView
The class UIAletrView allows you to display a modal window (animated) to inform and / or ask you something. The UIAlterView (view alerts) are very comfortable and easy to use. The handling of user response is solved by intercepting the index of the button pressed. To view a simple UIAlterView just write:
1 2 3 4 | / / Alert with a simple button, with no callback [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" cancelButtonTitle : @ "Annulla" otherButtonTitles : nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" cancelButtonTitle: @ "Cancel" otherButtonTitles: nil]; ; [MyAlert show]; ; [MyAlert release]; |
And 'possible to add additional buttons otherButtonTitles :
1 2 3 4 | / / Alert with two simple buttons, no callback [ [ UIAlertView UIAlertView MyAlert * = [[UIAlertView ; [MyAlert show]; ; [MyAlert release]; |
: To determine which button was pressed, simply add the delegate:self object initialization UIAlterView :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | / / Simple alert with two buttons and callbacks [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "Ok", nil]; ; [MyAlert show]; ; [MyAlert release]; / / The callback has the following syntax void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex buttonIndex ) { switches (buttonIndex) { : case 1: / / Code break; } } |
The callback alertView need to have that name, for more information see UIAlertViewDelegate
punteranno sempre a quella. With only the callbck alertView:clickedButtonAtIndex more UIAletrView will always point to that. Using the tag field of the object UIAletrView , we can determine what the "caller":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | / / Simple alert with two buttons and callbacks [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "Ok", nil]; ; myAlertA.tag = 1; ; [MyAlertA show]; ; [MyAlertA release]; / / [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView myAlertB * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "Ok", nil]; ; myAlertA.tag = 2; ; [MyAlertB show]; ; [MyAlertB release]; / / Multiple management UIAlertView void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex "Alert Tag: %i" , alertView.tag ) ; NSLog (@ "Alert Tags:% s", alertView.tag); "buttonIndex: %i" , buttonIndex ) ; NSLog (@ "buttonIndex:% s", buttonIndex); } |
Very short trick: stop NSTimer
The use of timers ( NSTimer ) to develop applications for Apple iPhone is very frequent, not only in making games. One of the problems with which one can collide is the asynchronicity of the timer, which can lead, during the arrest of one or more timers, the crash of our application. , si invoca la invalidate che, appunto, arresta il timer. When you want to stop one or more timers, where repeats is set to YES , you call the invalidate that, in fact, stop the timer.
Apple iPhone 3.0 SDK: Fixed bug on UIButton buttonWithType
As indicated in the post Apple iPhone SDK 3.0: first incompatibility of the Apple SDK 3.0 show different behaviors with respect to release 2.2.1. Support service for developers gave me the answer, and then the solution to the problem. . The answer was that the technical support [UIButton buttonWithType:] already called - inside - the initWithFrame . It follows that, according to tech support, writing:
From Actionscript to Objective-C
I thought it might be useful to those who have recently approached the development of applications for Apple iPhone, compare Adobe ActionScript - the language used in Adobe Flash and Adobe Flex, more common among the neo-programmers - and Objective-C language used by Apple to develop its applications. Objective-C is in effect an object-oriented language in the pure sense, not that Actionscript is not, but Objective-C is definitely a plus because it is an extension of ANSI C and its syntax is a mix between C / C + + and Smalltalk, is a true OO (Object-oriented language).
Apple iPhone SDK 3.0: first incompatibility
After you install the SDK 3.0 for Apple iPhone, evidently still not perfectly stable, I immediately noticed some problems, both in the compilation of the code is in the general XCode. The most important - which I promptly reported with a "home" to Apple, developers at the center - the creation of buttons through code. Here's an excerpt of the code is not compatible with SDK 3.0:
1 2 3 4 | [ [ UIButton buttonWithType : UIButtonTypeRoundedRect ] initWithFrame : CGRectMake ( 0 , 0 , 100 , 40 ) ] ; UIButton * myButton = [[UIButton buttonWithType: UIButtonTypeRoundedRect] initWithFrame: CGRectMake (0, 0, 100, 40)]; @ "Bottone" forState : UIControlStateNormal ] ; [MyButton setTitle: @ "Button" forState: UIControlStateNormal]; / / Other settings myButton ] ; [Self.view addSubview: myButton]; |
By filling out this code with the SDK 2.2.1 you get a classic button with the label "Button". With the SDK 3.0, the button is created, but the label disappears. la situazione sembra migliorare, nel senso che la label viene resa apparentemente in modo corretto. Using as buttonWithType the type UIButtonTypeCustom the situation seems to improve, in the sense that the label is apparently made correctly. It is still strange to the sudden failure of the type UIButtonTypeRoundedRect . I am still awaiting a response from Apple ... I just novelties; place!
The First: Available on iTunes
Hi phone
From today inaugurated a new section (category to be corrected) dedicated to developing applications on Apple iPhone! I state now that many of the items that will be publishing a "cut" in line with the spirit of this blog, that will be mostly for advanced users. However, as I have done this in other topics, try to be as clear as possible and, where necessary, put some "basic concept" useful to a wider audience.







Latest Comments
kOoLiNuS : @ Giovambattista Fazioli: thank you! more than willing!
Giovambattista Fazioli : @ kOoLiNuS: Quiet, you can probably anticipate that WPX Cleanfix will be free, and ...
kOoLiNuS : @ kOoLiNuS: a missing
and a 
kOoLiNuS : @ Giovambattista Fazioli: I subscribed to, but when I was my amateur use of the platform ...
Giovambattista Fazioli : @ kOoLiNuS: Yes, this is a known issue. Occurs when the tables in question are ...