This repository has been archived by the owner on Jul 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
accessors.m
61 lines (36 loc) · 1.53 KB
/
accessors.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Preferred */
// GDRestaurantCell.h
@property (strong, nonatomic) GDRestaurant *restaurant;
// GDRestaurantCell.m
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *subtitleLabel;
@property (strong, nonatomic) IBOutlet UIImageView *thumbnailImageView;
- (void)setRestaurant:(GDRestaurant *)restaurant {
_restaurant = restaurant;
self.titleLabel.text = restaurant.name;
self.subtitleLabel.text = restaurant.address;
self.thumbnailImageView.image = restaurant.image;
}
// GDRestaurantViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
GDRestaurantCell *cell = [GDRestaurantCell cell];
GDRestaurant *restaurant = [self restaurantAtIndexPath:indexPath];
cell.restaurant = restaurant;
// ...
}
/* Not Preferred */
// GDRestaurantCell.h
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *subtitleLabel;
@property (strong, nonatomic) IBOutlet UIImageView *thumbnailImageView;
// GDRestaurantViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
GDRestaurantCell *cell = [GDRestaurantCell cell];
GDRestaurant *restaurant = [self restaurantAtIndexPath:indexPath];
cell.titleLabel.text = restaurant.name;
cell.subtitleLabel.text = restaurant.address;
cell.thumbnailImageView.image = restaurant.image;
// ...
}