Last active
September 24, 2018 20:42
-
-
Save trupin/a92071db063cd17528dfbbcd973bbeeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "WSReviewViewController.h" | |
#import "Sample-Swift.h" | |
NS_ASSUME_NONNULL_BEGIN | |
@interface WSReviewViewController () <UITableViewDelegate, UITableViewDataSource> | |
@property (nonatomic, strong) UITableView *tableView; | |
@property (nonatomic, strong) NSArray<Review *> *reviews; | |
@end | |
@implementation WSReviewViewController | |
- (UITableView *)tableView { | |
if (!_tableView) { | |
_tableView = [UITableView new]; | |
_tableView.delegate = self; | |
_tableView.dataSource = self; | |
[_tableView registerClass:[ReviewTableViewCell class] forCellReuseIdentifier:NSStringFromClass([ReviewTableViewCell class])]; | |
_tableView.rowHeight = UITableViewAutomaticDimension; | |
_tableView.estimatedRowHeight = 140; | |
} | |
return _tableView; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.title = @"Reviews"; | |
self.view.backgroundColor = [UIColor whiteColor]; | |
self.edgesForExtendedLayout = UIRectEdgeNone; | |
[self.view addSubview:self.tableView]; | |
self.tableView.translatesAutoresizingMaskIntoConstraints = NO; | |
[NSLayoutConstraint activateConstraints:@[[self.tableView.topAnchor constraintEqualToAnchor:self.view.topAnchor], | |
[self.tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], | |
[self.tableView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], | |
[self.tableView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor]]]; | |
} | |
#pragma pragma - UITableViewDelegate | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return self.reviews.count; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ReviewTableViewCell class]) forIndexPath:indexPath]; | |
if ([cell isKindOfClass:[ReviewTableViewCell class]]) { | |
ReviewTableViewCell *reviewCell = (ReviewTableViewCell *)cell; | |
Review *review = self.reviews[indexPath.row]; | |
ReviewTableViewCellViewModel *viewModel = [[ReviewTableViewCellViewModel alloc] initWithReview:review]; | |
[reviewCell bindWithViewModel:viewModel]; | |
} | |
return cell; | |
} | |
@end | |
NS_ASSUME_NONNULL_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment