自从新的iOS 11更新后,我有一个应用程序在模拟器和设备上显示空白的tableview行。即使是应该存在的所有行的行分隔符也不会显示。如果我将模拟器更改为旧的iOS版本,则行将正常显示。没有对代码或故事板进行任何更改。
这些行仍然具有数据,这意味着我可以点击其中一个空白行,并且它将执行代码并包含我期望的信息。
似乎我放置在视图上并且不使用内置文本标签的其他场景都很好。只有这个使用内置文本标签的tableview类出了问题。
以下是我的tableview类代码...
这些行仍然具有数据,这意味着我可以点击其中一个空白行,并且它将执行代码并包含我期望的信息。
似乎我放置在视图上并且不使用内置文本标签的其他场景都很好。只有这个使用内置文本标签的tableview类出了问题。
以下是我的tableview类代码...
@interface BunkPickTableViewController ()
@end
@implementation BunkPickTableViewController
@synthesize appDelegate, delegate, bunkPassedValue;
- (void)viewDidLoad {
[super viewDidLoad];
UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CAGradientLayer *bgLayer = [BackgroundLayer tanGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
self.tableView.backgroundView = backgroundView;
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
self.title = @"Bunk Codes";
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.bunkArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor = [UIColor clearColor];
}
Bunk *bunkObj = [appDelegate.bunkArray objectAtIndex:indexPath.row];
cell.textLabel.text = bunkObj.bunkId;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
Bunk *bunkObj = [appDelegate.bunkArray objectAtIndex:indexPath.row];
[delegate dismissBunkPop:bunkObj.bunkId];
[self.navigationController popViewControllerAnimated:YES];
}
@end
viewDidAppear()
中调用tableView.reloadData()
来解决它。虽然会有一点闪烁,但总比不出现好。另外,我注意到当重复使用单元格时(即将它们滚动到屏幕外再滚回来),它们会重新出现。 - marcshilling