01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using the class in the Rental Manager application<br />

121<br />

ofType:@"plist"];<br />

cityMappings = [[NSDictionary alloc]<br />

initWithContentsOfFile:path];<br />

}<br />

properties =<br />

[[NSArray alloc] initWithObjects:<br />

[CTRentalProperty<br />

rentalPropertyOfType:TownHouse<br />

rentingFor:420.0f<br />

atAddress:@"13 Waverly Crescent, Sumner"],<br />

[CTRentalProperty<br />

rentalPropertyOfType:Unit<br />

rentingFor:365.0f<br />

atAddress:@"74 Roberson Lane, Christchurch"],<br />

[CTRentalProperty<br />

rentalPropertyOfType:Unit<br />

rentingFor:275.9f<br />

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

[CTRentalProperty<br />

rentalPropertyOfType:Mansion<br />

rentingFor:1500.0f<br />

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

[CTRentalProperty<br />

rentalPropertyOfType:Mansion<br />

rentingFor:2000.0f<br />

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

nil];<br />

c<br />

Create<br />

new<br />

object<br />

- (NSInteger)tableView:(UITableView *)tableView<br />

numberOfRowsInSection:(NSInteger)section {<br />

}<br />

return [properties count];<br />

- (UITableViewCell *)tableView:(UITableView *)tableView<br />

cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br />

static NSString *cellIdentifier = @"Cell";<br />

UITableViewCell *cell = [tableView<br />

dequeueReusableCellWithIdentifier:cellIdentifier];<br />

if (cell == nil) {<br />

cell = [[[UITableViewCell alloc]<br />

initWithStyle:UITableViewCellStyleSubtitle<br />

reuseIdentifier:cellIdentifier]<br />

autorelease];<br />

}<br />

CTRentalProperty *property =<br />

[properties objectAtIndex:indexPath.row];<br />

int indexOfComma = [property.address<br />

rangeOfString:@","].location;<br />

NSString *address = [property.address<br />

substringToIndex:indexOfComma];<br />

NSString *city = [property.address<br />

substringFromIndex:indexOfComma + 2];<br />

d<br />

Update<br />

the<br />

method

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

Saved successfully!

Ooh no, something went wrong!