01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sample application<br />

225<br />

rentingFor:275.9f<br />

atAddress:@"17 Kipling Street, Riccarton"],<br />

[CTRentalProperty rentalPropertyOfType:Mansion<br />

rentingFor:1500.0f<br />

atAddress:@"4 Everglade Ridge, Sumner"],<br />

[CTRentalProperty rentalPropertyOfType:Mansion<br />

rentingFor:2000.0f<br />

atAddress:@"19 Islington Road, Clifton"],<br />

nil];<br />

filteredProperties = [[NSMutableArray alloc]<br />

initWithArray:allProperties];<br />

Create array for<br />

filtered properties<br />

}<br />

self.navigationItem.rightBarButtonItem =<br />

[[UIBarButtonItem alloc]<br />

initWithTitle:@"Filter"<br />

style:UIBarButtonItemStylePlain<br />

target:self<br />

action:@selector(filterList)];<br />

- (void)filterList {<br />

UIAlertView *alert =<br />

[[UIAlertView alloc] initWithTitle:@"Filter"<br />

message:nil delegate:self<br />

cancelButtonTitle:@"Cancel"<br />

otherButtonTitles:nil];<br />

Add “Filter”<br />

button<br />

[alert addButtonWithTitle:@"All"];<br />

[alert addButtonWithTitle:@"Properties on Roads"];<br />

[alert addButtonWithTitle:@"Less than $300pw"];<br />

[alert addButtonWithTitle:@"Between $250 and $450pw"];<br />

Create alert for<br />

filtered options<br />

}<br />

[alert show];<br />

[alert release];<br />

- (void)alertView:(UIAlertView *)alertView<br />

clickedButtonAtIndex:(NSInteger)buttonIndex<br />

{<br />

if (buttonIndex != 0)<br />

{<br />

NSPredicate *predicate;<br />

Check user doesn’t<br />

click Cancel<br />

Create filter<br />

predicate<br />

switch (buttonIndex) {<br />

case 1:<br />

predicate = [NSPredicate<br />

predicateWithFormat:@"TRUEPREDICATE"];<br />

break;<br />

case 2:<br />

predicate = [NSPredicate<br />

predicateWithFormat:@"address CONTAINS 'Road'"];<br />

break;<br />

case 3:<br />

predicate = [NSPredicate<br />

predicateWithFormat:@"rentalPrice < 300"];<br />

break;<br />

case 4:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!