Try the search, it's linked to some great forums

Wednesday, June 20, 2012

Beginning JavaScript tutorials

This is an example pageHere we're starting a series of JavaScript (JS) tutorials with references and whatever;
The following snippets are from http://www.javascriptkit.com/javatutors/primer3.shtml

Welcome to the JavaScript course!


Add to Existing Text

Replace Existing Text

Friday, June 15, 2012

UIPickerView snippet



The UIPickerView is a simple & pretty UI element for selecting items.  It mimics the wheels on a slot machine.  Below is the snippets that allow for the configuring of the displayed view.  Each wheel is a component, and the data items in each wheel are defined as a row element.

                          
define the pickerView and an array for the data to be displayed
in FlipsideViewController.h -
@property (strong, nonatomic) IBOutlet UIPickerView *heightPicker;
@property (strong, nonatomic) NSArray *pickerItems;

implement the required delegate and dataSource methods. 
in FlipsideViewController.m -
#pragma mark ---- UIPickerViewDataSource delegate methods ----

// returns the number of columns to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
}

// returns the number of rows
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [self.pickerItems count];
}

#pragma mark ---- UIPickerViewDelegate delegate methods ----

// returns the title of each row
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [self.pickerItems objectAtIndex:row];
}

// gets called when the user settles on a row
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// Picks out the component & it's value 
    NSString *componentValue = [self.pickerItems objectAtIndex:row];
   
// assigns row values to feet or inches & calculates the fractional feet
    if (component == 0) {
        feetComponent = [componentValue floatValue];
    }
    if (component == 1) {
        inchesComponent = [componentValue floatValue];
    }
// calculates fractional feet value   
    flagHeight = feetComponent + (inchesComponent / 12);
    self.flipsideInfo.text = [NSString stringWithFormat:@"= %2.2f feet", flagHeight];    
}
Oh, and don't forget to synthesize the NSArray & UIPickerView instance variables.

Monday, June 11, 2012

Delegation - passing info between controllers

The flipside template in Xcode provides probably the simplest implementation of a custom delegate that there is.  It allows the programmer to pass data from the flipside (settings data, flagHeight) to the MainView.  Here it is;

Create the delegate protocol and it's methods, define the delegate property and define a property to pass (flipsideInfo);
in FlipsideViewController.h -
@class FlipsideViewController;    // forward reference

@protocol FlipsideViewControllerDelegate   // delegate name & required method
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@interface FlipsideViewController : UIViewController

@property (weak, nonatomic) id delegate;
@property (strong, nonatomic) IBOutlet UITextField *flipsideInfo;  // data to pass on

Oh, and don't forget to synthesize the delegate;
in FlipsideViewController.m - 
@implementation FlipsideViewController
@synthesize delegate = _delegate;

Set the MainViewController to conform the the delegate, FlipsideViewControllerDelegate;
in MainViewController.h -
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>

Implement the required delegate method flipsideViewControllerDidFinish: 
in MainViewController.m -
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    self.myAssistantLabel.text = controller.flipsideInfo.text;  // flipsideInfo is a property of the flipsideVC
    [self dismissModalViewControllerAnimated:YES];
}

And that's all she wrote!

Sunday, June 10, 2012

Delegation - implementing canned delegate protocols

Building on the prior post on creating your own delegates, this one describes the simple process of implementing a delegate provided to you by Xcode (or someone else I guess)

Delegation - creating your own delegate

Delegation is a way to have an unrelated class (object) perform methods for another class (object).  A delegate is a protocol, and you declare the delegate in the class that you want it to operate on.  The following example shows all of the code details for building your own custom delegate.  Many delegates come prepackaged in iOS and you implement them in a similar way shown below this example.

You declare a delegate in the class header file either above or below the @interface code.  You give it a name & list the methods that it can perform.  The methods can either be optional or required.  Required is the default.   The (float)smileForFaceView: is a required method that must be implemented by whoever declares themselves conforming to the delegate. NOTE; that we send a copy of ourself (FaceView) along with the method.  This allows the other object to look at the FaceView object.
in FaceView.h -
@protocol FaceViewDataSource
- (float)smileForFaceView:(FaceView *)sender;
@end

@interface FaceView : UIView

then in a class that you want to conform to the delegate, you add the following to it's @interface line.
in HappinessViewController.m - (for a private delegation??)
 @interface HappinessViewController()

or in HappinessViewCntroller.m - (more common way to do)
  @interface HappinessViewController

 We next need to declare ourselves as the delegate like;
in FaceView.h - (?? declares a property of FaceView.  This allows the conforming class to ??
@property (nonatomic, weak) IBOutlet id dataSource;

We then also need to declare the new class as the delegate??
in HappinessViewController.m - the method - - (void)setFaceView:(FaceView *)faceView
self.faceView.dataSource = self;

Now the final thing to do is just implement the required methods of this delegate in the conforming class (HappinessViewController).  We then implement smileForFaceView like;
in HappinessViewController.m - 
- (float)smileForFaceView:(FaceView *)sender   // this just convert the happiness property to +/- 1
{
    return (self.happiness - 50) / 50.0;
}

And finally ??????;
in FaceView.m, the - draawRect method - 
    float smile = [self.dataSource smileForFaceView:self]; // delegate our View's data
 See the next Post for implementing canned delegates;

 (as always many thanks to the incomparable Paul Hegerty and his Stanford iOS lectures




Tuesday, June 5, 2012

Mac magic

These are magic Mac keystrokes and other shortcuts;

Screen capture - CMD-CNTRL-SHIFT-4  captures an area of the screen to the clipboard for pasting or whatever.  Here's the URL for a more complete discussion.  Screen captures

 Force Quit - CMD-OPTION-ESCAPE allows closing of locked up programs.  Can also be done from the bottom menu by CNTRL-clicking the icon

Mac freeware source -  http://opensourcemac.org/