Wednesday, September 28, 2011

Do you know Objective-C? UITextField



Today we are going to learn how to use UITextField and how we have to do if we want to share data between two or more views.
To begin with, UITextField is no more than a place where we can write anything by using keyboard, to use any action with it.  If we want to use a UITextField, we have to know we need a method to display the keyboard to setting UITextField. Also, the UITextFieldDelegate protocol defines the messages sent to a text field delegate as part of the sequence of editing its text. This is why we set the UIView as delegate of the UITextField. We get it by creating the following method:


We use two UITextField with our UILabel which will show UITextField's contents. For this example we use a button to hide the keyboard, but it can be designed to have to whatever behavior its.


The method resignFirstResponder makes the UITextField loses focus and hides keyboard. After actions and objects have been designed we can set the NIB file.


We design a navigation bar with a button which makes to lose focus to the selected UITextField and then, textFieldDidEndEditing will be called to set the UILabel. Also we link the keyboard method when UITextField Did End On Exit like is showing in the past image.


By last, if we want to share data between two UIViews, we have to instantiate a objet of AppDelegate like this:  (iAccesoAppDelegate *)[[UIApplication sharedApplicationdelegate]. Also we have to set the shared data with @property as readwrite and copy. With this, we are setting the UIApplication as delegate of our View where we can have shared data, and both could access to them.

Tuesday, September 27, 2011

iAccess: First screenshots


My first App for iPhone is a simplified menu based in direct access which will be set with  a default group of accesses and, they could be edited like user wants.
Followed this, some screenshorts of the App which is going to be available in Apple Store soon.


               




Thursday, September 22, 2011

Do you know Objective-c?: How navigate in UITableView

As we saw how we can define a UITableView, set its properties and personalize it, now we are going to learn how to navigate in our UITableView designed in the post which we talked about UITableView, which we customize with two rows and sections that depended by the contents of array.
At first we have to define the UINavigationController in one of our events: ApplicationDidFinishLaunching. We do it like that:


After this, we have to add a UIViewController to our project which will be personalized with a method of writing in a UILabel and change it with a UIButton like our 'HelloWorld' example.


We have to select the correct subclass for our code:











We continue adding variables and methods to the new class we have created. We define an UILabel, UIButton with their respective methods set them in files .h & .m


The appearance of our new View will be customized with a button and a label as we said.


By last, we have to add what happens when a row was select. We had two arrays, that's why I evaluate what section I select it.


After all, we obtain a simple application like this:




Monday, September 19, 2011

Do you know Objective-c? Properties

I started publishing posts by forgiving a feature of Objective-C really usefull for our application development allow us to generate automatically getters/setters. Also we usually have to think that our code have to be straightforward and it could be generalized. Properties are a kind of virtual member variables which offer us all we have said. This is what it look without use properties:


After we use properties in our code, it seems like this:


The word "retain"in parenthesis the setter function: it should retain the input value. Rest of the line specifies type and name of the property. After this, the class definition as follow:


We can use setter an getter methods which are generate by the @synthesize directive. This directive is used to instantiate the property Also we use the dot syntax to set or get a value as we used.
With this example, we see properties are so powerful feature to use in our software developer. Next post will explain the attributes that a property can be have.


Monday, September 12, 2011

Do you know Objective-c? UITableView

Today we will see what is a UITableView, how define it and do a customization of them. UITableView is not more than a simple view of a list of information. We start defining a UITableView object in .h file of our proyect.
Later, to define it, mandatorily, we have to define methods that define basic properties of TableView, that in this case, will be the number of rows&sections that contain, and generate cells that contain the rows. The methods are:

We define the number of sections in UITableView, number of rows, and we access to cells's rows, initializing if necessary. Also, we add text to cell. With it we obtain a table, with two sections and two rows for each section with the word "prueba" that will be displayed.
After know basic operation of TableView, we can do a customization type  basic and usefull of it.
We can define names of headers and footers of sections,  define a determinate content for each section, with a array of objects (text, images, views, etc...). For it, we have modified the methods numberOfRowsInSection to give back the array content. We have create titleForHeaderInSection, that generate a title in fuction of the section and the method cellForRowAtIndexPath where the title for each cell will be the content of array depending of section. We haven't to forget add NSArray objects to .h file to our proyect. Finally, as it show in the video, we can see the result.




Sunday, September 4, 2011

Do you know Objective-c? UIApplication&UIView

Today we will see essential elements that make up all iPhone application and will serve as a base to mount your application (actions and appearance): UIApplication and UIView

I) UIApplication: 
UIApplication is, the entry point of the application, and is responsible for initializing and displaying a UIWindow, uploading this to load the first view (UIView). UIApplication manages the lifecycle of the application, using the UIApplicationDelegate, which manages the events received by the UIApplication. An example of events would start the application, close it, when a call is received while application is running, etc... So the events to handle are:
  • WillChangeStatusBarFrame: It will change the frame of the status bar.
  • DidChangeStatusBarOrientation: Change the orientation of the status bar.
  • WillChangeStatusBarOrientation:duration:It will change the orientation of the status bar and the duration parameter indicates how the animation will last. 
  • AandleOpenURL: Tells the delegate who wants to open a URL.
  • ApplicationDidBecomeActive: When the app is interrupted for whatever reason, will run in time to end this interruption.  
  • ApplicationDidFinishLaunching: Runs when the application has finished loading.
  • ApplicationDidReceiveMemoryWarning: When the device will run out of memory reaches, giving a "second chance" to free up space.
  • ApplicationSignificantTimeCharge: Runs to a significant change in the time during the performance of your application.  
  • ApplicationWillResignActive: Runs to a significant change in the time during the performance of your application.
  • ApplicationWillTerminate: Runs before it goes do idle.
  • ApplicationDidEnterBackground: The application will go into the background but if the application does not have multitasking implemented this method should save the state of the application, freeing the memory as it is on "pause" in the background when the user re-enters be in the sate in which it was but when in this "pause" if the memory the OS needs to close.
  • ApplicationWillEnterForeground: The application returns to the fore.
 II) UIView: 
 For each interface file .xib which has a UIView, will correspond to the handler classes .xib. UIView inherits UIView and will manage everything related to the associated view. UIViewController also manages the life cycle of UIView with the following events:
  • didReceiveMemoryWarning: When the controller receives a notice of memory. 
  • DidRotateFromInterfaceOrientation: Called after the view has rotated. 
  • WillRotateToInterfaceOrientation:duration: Called when the view starts to rotate, the duration indicates how long will it take to rotate.  
  • ViewDidAppear: Called after the view has emerged.  
  • ViewDidDisappear: Called after the view has disappeared.  
  • ViewDidLoad: Called after the view has been loaded into memory. 
  • ViewWillAppear: It is invoked just before the view appears. Is invoked just before the view disappears. 
  • WillAnimateFirstHalfOfRotationToInterfaceOrientation:duration: Runs before the rotation of the firs half of the interface and the duration will last.
  • WillAnimateSecondHalfOfRotationFromInterfaceOrientation:duration: Runs before the rotation of the second half of the interface and the duration will last. 
Now we know the basic operation of a UIView and UIApplication, we will see ViewTableController and ViewTable, which will be useful to develop a set of views to "surf" for our app.