ios development (part 1)
Post on 18-Nov-2014
627 Views
Preview:
DESCRIPTION
TRANSCRIPT
iOS Development (Part I)COMPILED BY: ASIM RAIS SIDDIQUI(asim.r.sidddiqui@gmail.com)
Goals of the Lecture
Familiarization with XCode IBOutlet & IBAction Types of Controls Common Properties of Xcode Controls
Handling Actions & Controls
Use of Text Fields, Labels, Sliders, Switch Buttons
Xcode Common Sections
The Toolbar
activity view
assistant view
Symbol navigator
Search navigator
Issues navigator
The Toolbar
Project Navigator
Symbol navigator
Issues navigator
The Jump Bar
What’s in the Nib File?
Every nib file starts off with the same two icons, File’s Owner and First Responder. They are created automatically and cannot be deleted.
Outlets and actions
A controller class can refer to objects in a nib file by using a special kind of property called an outlet.
Interface objects in our nib file can be set up to trigger special methods in our controller class. These special methods are known as action methods (or just actions).
@property (nonatomic, retain) IBOutlet UIButton *myButton;
This example is an outlet called myButton, which can be set to point to any button in Interface Builder.
Outlets and actions
Actions
In a nutshell, actions are methods that are declared with a special return type, IBAction, which tells Interface Builder that this method can be triggered by a control in a nib file. The declaration for an action method will usually look like this:
- (IBAction)doSomething:(id)sender;
or like this:
- (IBAction)doSomething;
Action with Multiple Buttons
- (IBAction)buttonPressed:(UIButton *)sender {
NSString *title = [sender titleForState:UIControlStateNormal]; statusText.text = [NSString stringWithFormat:@"%@ button pressed.", title];
}
Practical
Active, Static, and Passive Controls
Buttons : Active
ImageView : Static
Passive : TextField
Some general control properties
Tag
Interaction Checkboxes
The Alpha Value
Background
Placeholder
Clear Button
Return Key popup
Auto Enable Return Key
Return key secure
Keyboard
Handling actions with Controls
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *nameField; @property (strong, nonatomic) IBOutlet UITextField *numberField;
- (IBAction)textFieldDoneEditing:(id)sender;
@end
- (IBAction)textFieldDoneEditing:(id)sender { [sender resignFirstResponder];
}
Adding the Slider and Label
- (IBAction)sliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)roundf(slider.value);
sliderLabel.text = [NSString stringWithFormat:@"%d", progressAsInt];
}
The first line in the method assigns sender to a UISlider pointer so that the compiler will let us use UISlider methods and properties without warnings.
top related