From 695979eac4d5c471e4e4ccdf6f7aa329e83082a6 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Sun, 11 Mar 2018 21:09:06 +0200 Subject: [PATCH] Refactors -[tableView:cellForRowAtIndexPath:] (#3326) Fixes static analyzer issue complaining -[tableView:cellForRowAtIndexPath:] returns nil. --- .../Objective-C/DemoBaseViewController.m | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/ChartsDemo/Objective-C/DemoBaseViewController.m b/ChartsDemo/Objective-C/DemoBaseViewController.m index c5908a844c..4e6392a91d 100644 --- a/ChartsDemo/Objective-C/DemoBaseViewController.m +++ b/ChartsDemo/Objective-C/DemoBaseViewController.m @@ -170,7 +170,8 @@ - (IBAction)optionsButtonTapped:(id)sender _optionsTableView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.9f]; _optionsTableView.delegate = self; _optionsTableView.dataSource = self; - + [_optionsTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; + _optionsTableView.translatesAutoresizingMaskIntoConstraints = NO; NSMutableArray *constraints = [[NSMutableArray alloc] init]; @@ -224,23 +225,14 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - if (tableView == _optionsTableView) - { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; - if (!cell) - { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; - cell.backgroundView = nil; - cell.backgroundColor = UIColor.clearColor; - cell.textLabel.textColor = UIColor.whiteColor; - } - - cell.textLabel.text = self.options[indexPath.row][@"label"]; - - return cell; - } - - return nil; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; + cell.backgroundView = nil; + cell.backgroundColor = UIColor.clearColor; + cell.textLabel.textColor = UIColor.whiteColor; + + cell.textLabel.text = self.options[indexPath.row][@"label"]; + + return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath