Graphics Reference
In-Depth Information
time rather than preloading them using the
-imageNamed:
method. We've also added some
layer shadows to make our list a bit more visually appealing. Listing 12.1 shows the initial,
naive implementation.
Listing 12.1
A Simple Contacts List Application with Mock Data
#import
"ViewController.h"
#import
<QuartzCore/QuartzCore.h>
@interface
ViewController
() <UITableViewDataSource>
@property
(
nonatomic
,
strong
)
NSArray
*items;
@property
(
nonatomic
,
weak
)
IBOutlet
UITableView
*tableView;
@end
@implementation
ViewController
- (
NSString
*)randomName
{
NSArray
*first =
@[
@"Alice"
,
@"Bob"
,
@"Bill"
,
@"Charles"
,
@"Dan"
,
@"Dave"
,
@"Ethan"
,
@"Frank"
]
;
NSArray
*last =
@[
@"Appleseed"
,
@"Bandicoot"
,
@"Caravan"
,
@"Dabble"
,
@"Ernest"
,
@"Fortune"
]
;
NSUInteger
index1 = (
rand
()/(
double
)
INT_MAX
) * [first
count
];
NSUInteger
index2 = (
rand
()/(
double
)
INT_MAX
) * [last
count
];
return
[
NSString
stringWithFormat
:
@"%@ %@"
, first[index1], last[index2]];
}
- (
NSString
*)randomAvatar
{
NSArray
*images =
@[
@"Snowman"
,
@"Igloo"
,
@"Cone"
,
@"Spaceship"
,
@"Anchor"
,
@"Key"
]
;
NSUInteger
index = (
rand
()/(
double
)
INT_MAX
) * [images
count
];
return
images[index];
}
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
//set up data
NSMutableArray
*array = [
NSMutableArray
array
];
for
(
int
i =
0
; i <
1000
; i++)
{
//add name