iTableView单元格内容在iOS 9上加载正常,但在iOS 8上加载不正常

iTableView单元格内容在iOS 9上加载正常,但在iOS 8上加载不正常,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我遇到过这样一个事件:iOS 9上的UITableView单元格内容加载正常,但iOS 8上没有。我已经在模拟器和设备上验证了这一点 - (void)viewDidLoad { [super viewDidLoad]; self.tableView.estimatedRowHeight = 140.0; self.tableView.rowHeight = UITableViewAutomaticDimension; _allItems = [[NSDictionary alloc] in

我遇到过这样一个事件:iOS 9上的
UITableView
单元格内容加载正常,但iOS 8上没有。我已经在模拟器和设备上验证了这一点

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
我已尝试在
viewDidLoad
上加载数据,
viewwillbeen
,甚至在
viewdidbeen
中加载数据,但仍然相同。我尝试了
dispatch\u async
来重新加载
tableView
,但仍然是一样的

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
检查下面的图像以查看我遇到的问题

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
但是,当我点击星星的位置时,星星的
UIView
突然出现

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
这是我的
UITableView
控制器代码

@interface EvalTableViewController ()

@property (strong, nonatomic) NSDictionary *allItems;
@property (strong, nonatomic) NSArray *items;
@property (strong, nonatomic) NSMutableArray *ratings;

@end

@implementation EvalTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.estimatedRowHeight = 140.0;
    self.tableView.rowHeight = UITableViewAutomaticDimension;

    _allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    
    _items = nil;
    _items = [_allItems objectForKey:_currentEval];

    [self loadRatings];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"itemCellId";
    ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];

    cell.item.text = _items[indexPath.row];
    cell.ratingView.value = ((NSNumber *)_ratings[indexPath.row]).floatValue;
    [cell bringSubviewToFront:cell.ratingView];
    [cell.ratingView addTarget:self action:@selector(updateRating:) forControlEvents:UIControlEventValueChanged];
    [cell layoutSubviews];
    return cell;
}

- (void)updateRating:(HCSStarRatingView *)ratingView {
    long indexOfRatingView = [self.tableView indexPathForCell:(ItemTableViewCell *)[[ratingView superview] superview]].row;
    [_ratings replaceObjectAtIndex:indexOfRatingView withObject:[[NSNumber alloc] initWithFloat:ratingView.value]];
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexOfRatingView inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}

- (void)loadRatings {
    _ratings = nil;
    _ratings = [[NSMutableArray alloc] init];
    for (int i = 0; i < _items.count; i++) {
        [_ratings addObject:[[NSNumber alloc] initWithFloat:1.0]];
    }
}
}
- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
我是iOS应用程序开发新手,希望你能帮助我

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

谢谢。

尝试将此代码添加到tableViewCell.m文件中的awakefromnib方法中(导入hcsstaratingview后)。还可以尝试在模拟器中的调试模式,以查看第一次触摸前视图是否存在

HCSStarRatingView *starRatingView = [[HCSStarRatingView alloc] initWithFrame:initWithFrame:CGRectMake(0, 0, self.ratingView.frame.size.width,  self.ratingView.frame.size.height)];
- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

我想将子视图带到前面可能有问题

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
请在单元格中为索引路径处的行尝试此方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"itemCellId";
ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];

cell.item.text = _items[indexPath.row];
cell.ratingView.value = ((NSNumber *)_ratings[indexPath.row]).floatValue;
//[cell bringSubviewToFront:cell.ratingView];
[cell.ratingView addTarget:self action:@selector(updateRating:) forControlEvents:UIControlEventValueChanged];
[cell layoutSubviews];
return cell;
}
- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
若它仍然不能正常工作,那个么就添加这个代码并再次测试

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

希望这能解决您的问题。

在调用
[self-loadRatings]后,您需要重新加载表数据。请尝试一下。

似乎我们过去解决问题的所有努力都更多地集中在加载单元格上,而不是
UITableViewCell
本身

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
我发现问题在于我对品牌和星级的限制。我刚刚在我的星级评定中添加了一个
高度
约束,当tableView出现时,它就会显示出来。我还需要放入
[self.tableView reloadData]在我的
视图中显示
方法

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
但是,
UITableViewCell
最初以固定高度显示,然后在视图呈现给用户后调整其高度,这可能对用户没有吸引力。当我点击星级时,tableView会滚动

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
但无论如何,这给了我解决问题的希望

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}
我只是觉得很奇怪。因为,如果这是一个约束或布局错误,为什么它在iOS 9上运行良好,而在iOS 8上运行不好

- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}

非常感谢。

您可以发布您的代码吗?您使用哪个类进行星级评定?再次检查我的问题,我已经添加了代码。@abhi1992我正在使用我发现的星级评定控件调用
[单元格布局子视图]。顺便说一句,你能发布
ItemTableViewCell
code吗?:)我试过你的建议,但还是不走运。谢谢。请在Xcode的3d视图中查看您的屏幕。是否有任何视图隐藏您的评级视图?正如阿披谢克·古普塔所说,在负载评级之后,还要尝试重新加载数据。这与层次模式相同吗?我使用了层次模式,但子视图似乎根本没有渲染。是否在“分级”视图中使用不同的开始图像来显示空星星?我没有使用任何图像来渲染星星分级。这些图形都是根据我在控件中了解的内容进行编码的。我尝试添加initWithFrame,但仍然没有效果。如何使用调试模式?感谢您在模拟器中运行应用程序,然后您可以在底部看到一个视图层次模式按钮()。查看上面的链接。我刚刚尝试过,但似乎根本没有呈现星级。使用层次模式后,模拟器将变得无响应。在第一次以层次模式运行时,星级的帧不可见。我再次运行并点击视图以显示它。然后,我使用了层次结构模式,我可以在那里看到星级,以及所有其他星级框架,但没有绘图。使用层次结构模式后,模拟器变得无响应。这是默认行为。请检查:ItemTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];并替换为dequeueReusableCellWithIdentifier:
- (void)viewDidLoad 
{

[super viewDidLoad];
self.tableView.estimatedRowHeight = 140.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

_allItems = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AssessmentItems" ofType:@"plist"]];    

_items = nil;
_items = [_allItems objectForKey:_currentEval];

[self.tableView reloadData];
[self loadRatings]; 

}