Archive

Posts Tagged ‘xCode’

iPhone Date Range Editor

February 19th, 2010 1 comment

Date range editing is a useful when dealing with calendars or time periods, the iPhone calendar provides a nice simple way of editing a date range. Just open up the Calendar hit the + button and edit the events date range, you get a lovely screen that looks like the image below:



Calendar Date Rang Editor

Unfortunately UIkit does not provide a basic control to edit a date range editor, it does provide the UIDatePicker which can be used to build your own date range editor and this is what I have set about to do. The basic idea is to emulate the basic functionality implemented in the calendar date range editor, i.e. The start and end dates can be selected which in turn alters the date displayed in the UIDatePicker and the control provides basic error detection changing the start date red when invalid and prevent savings if there is an invalid date range.

The following is the result of my attempt to recreate this control in a simple and customisable way, the header file below is rather long but there are only a few items exposed to interface builder to make it easy to setup.

//
//  UIViewControllerDateRangeEditor.h
//  UIViewControllerDateRangeEditor
//

#import

@interface UIViewControllerDateRangeEditor : UIViewController
{
@private

// ----------------------------------------
// control objects
// ----------------------------------------
IBOutlet UIBarButtonItem *	leftBarButton;          // Navigation Button to be used on the left    : Cancel
IBOutlet UIBarButtonItem *	rightBarButton;      // Navigation Button to be used on the right  : Save
// ----------------------------------------

// ----------------------------------------
// Display Content
// ----------------------------------------
IBOutlet UILabel  *			startLabel;                   // start label : used for highlighting and is not altered
IBOutlet UILabel  *			startDate;                     // start date label : used for highlighting and contains the current start date

IBOutlet UILabel  *			endLabel;                     // end label : used for highlighting and is not altered
IBOutlet UILabel  *			endDate;                      // end date label : used for highlighting and contains the current end date
// ----------------------------------------

// ----------------------------------------
// control objects
// ----------------------------------------
IBOutlet UIDatePicker *		datePicker;       // date picker : link the value change to the dateChanged action
// ----------------------------------------

// ----------------------------------------
// Start Date Colors
// ----------------------------------------
UIColor *					normalColor;
UIColor *					highlightColor;
// ----------------------------------------

// ----------------------------------------
// Buttons
// ----------------------------------------
IBOutlet UIButton *			buttonStart;              // button that is to be highlighted at the start
UIButton *					buttonSelected;
UIImage  *					buttonImage;
// ----------------------------------------

// ----------------------------------------
// Date Formatter
// ----------------------------------------
NSDateFormatter *			dateFormatter;
// ----------------------------------------

// ----------------------------------------
// current dateValue
// ----------------------------------------
NSTimeInterval				startTimeInterval;
NSTimeInterval				endTimeInterval;

NSTimeInterval				minTimeInterval;
NSTimeInterval				maxTimeInterval;
// ----------------------------------------

// ----------------------------------------
Boolean						editingStartDate;
Boolean						savePressed;
Boolean						delayReset;
// ----------------------------------------
}

@property (nonatomic) NSTimeInterval startTimeInterval;
@property (nonatomic) NSTimeInterval endTimeInterval;

@property (nonatomic) NSTimeInterval minTimeInterval;
@property (nonatomic) NSTimeInterval maxTimeInterval;

@property (nonatomic, readonly) Boolean savePressed;

- (void) reset;

- (IBAction) cancel:(id)sender;
- (IBAction) save:(id)sender;

- (IBAction) dateChanged:(id)sender;

- (IBAction) selectStartDate:(id)sender;
- (IBAction) selectEndDate:(id)sender;

@end

The View controller provided with this article should permit you to create your own custom date range editor using interface builder, this can either be loaded manually or via the main nib. The sample project provide demonstrates how the view controller is setup and how you can use it in your own project.



Sample Images

Download : UIViewControllerDateRangeEditor.h, UIViewControllerDateRangeEditor.m

Sample Project : UIViewControllerDateRangeEditor

Example Usage :


// -------------------------------------------------------------------
// load  the date range editor and push it onto the view stack
// -------------------------------------------------------------------
- (IBAction) editDateRange:(id)sender
{
if ( editor == nil )
{
editor = [[UIViewControllerDateRangeEditor alloc] initWithNibName:@"UIViewControllerDateRangeEditor" bundle:nil];
editor.title = @"Edit";
}

editor.startTimeInterval = startTime;
editor.endTimeInterval   = endTime;

[[self navigationController] pushViewController:editor animated:TRUE];
}

// -------------------------------------------------------------------
// when the controller returns from the editor copy the date out if save has been
// pressed and reset the controller.
// -------------------------------------------------------------------
- (void) viewWillAppear:(BOOL)animated
{
if ( editor )
{
if ( editor.savePressed )
{
startTime = editor.startTimeInterval;
endTime = editor.endTimeInterval;
}

[editor reset];
}
}

As always the source is provided as is and use it at your own risk, feel free to alter and extend as you see fit. Have fun.

AD-HOC Automation

October 13th, 2009 No comments

AutomatorI recently had a lot of trouble with building and distributing AD-HOC builds, with that in mind I set out to not to fall into the same trap twice (lots of time wasted) and automate the process using a shell script.  This would be able to compile the desired build configuration, grab any documentation I wanted to go along with said build and include a valid mobileprovision (preferable the one it was built with). The script would then package up all this data into an object that could be directly distributed to the test group.

The result is a simple script that you can download it here.

I struggled with the selection of the correct mobileprovision, I initially had the provision file in the project and just directly copied it, which worked fine for a while. I then ran into the problem of having to remember to update it when adding another device to the provision (after I copied to the organizer I would also have to update all my projects). The solution that I ended up using, was to use grep to search the provision folder for the name’s contained inside mobileprovision file and then copy that one into the output folder. It’s not a perfect solution but better than having two copies of the provision lying around, one in the project and another in the directory used by the Organizer. If you would like to use the script please feel free (you will need to alter it slightly for your project). I am in the process of writing up some simple steps on how to integrate the script into your xcode project, they should be up soon.

Note : The Package script creates both a zip and a dmg, they both contain the same information I did it just for completeness.

[UPDATE :: Setup Instructions can be found here]

To Change a Product Name in xCode

January 9th, 2009 No comments

xCode Development ToolI put together a project template at the end of last year and set it up so that I could create a brand new project from it via xCode. Unfortuanttly the Product Name never seemed to be updated.

So as a reminder to me in the future the simple steps to change the product name are as follow:

1) Open xCode + Desired Project.
2) Select the current Targets and right click.
3) Select “Get Info”.
4) Select the “Build” tab.
5) Search for “Product Name” (or find it under “Packaging”).
6) Change it to the desired product name.

I’m sure I must be able to have this automaticlly configered when a new project is created, but thats something to do later. 

Quick fix gallore, 
Bert

Template revisited.

December 10th, 2008 1 comment

I spent most of yesterday re-working the template I created, sorting it out and cleaning up the code so that it’s nice an easy to integrate the game.

On that note I found out how to make the project into a template for xCode, way to easy and I’m sure I missed some thing.

How to make a template:
1) Create your project and set it up the way you want it.
2) Compile and make sure it runs, then delete the build folder.
3) Create a new folder in “Developer/Platforms/iPhoneOS.platform/Developer/Library/XCode/Project Templates/“.
3) Copy the project into your new folder.
4) Open xCode and create a new project.
5) Select your template.

Seemed way to easy but I thought I’d blog about it so I can find how to do it again.

The only thing I’m still not happy with is the high score view, still need to sit down and think it through more…

On other notes I fixed the selection of the collect tile and the time reduction when the level is changed, and decided to put in a time bonus for the level completion.

Sorry for the lack of picktures I’ll try and add a UI flow diagram later. :)