iOS 8自定义表格视图单元格选择

时间:2015-04-23 14:40:17

标签: ios objective-c uitableview row selection

我的自定义单元格存在一些问题。我用自己的xib文件创建了新的自定义TableViewCell。表载荷和数据正在所有单元格中填充 - 这一切都可以。但是当我在iOS 8及更高版本的设备和模拟器中运行我的应用程序时,select方法永远不会触发。使用iOS 7.x在设备和模拟器上运行应用程序时,不会发生此问题。这是CustomCell.m文件的代码

- (void)awakeFromNib {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}

这是mu CustomCell.h文件

@interface CustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *directionImage;
@property (weak, nonatomic) IBOutlet UILabel *distanceLbl;
@property (weak, nonatomic) IBOutlet UILabel *pathDescriptionLbl;

以下是ViewController的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"row selected");
}

- (NSInteger)tableView:(UITableView *)tableView   numberOfRowsInSection:(NSInteger)section{
return [steps.stepsData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellIdentifier = @"directionsCell";
DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil){
    NSString *cellNib = [Utilities getDirectionCellNib];
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:cellNib owner:self options:nil];
    cell =  [topLevelObjects objectAtIndex:0];
}

if(indexPath.row == 0 || (indexPath.row % 2 == 0)){
    cell.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1.0];
}else{
    cell.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0];
}
cell.directionImage.image = nil;
cell.distanceLbl.text = @"";
cell.pathDescriptionLbl.text = @"";

if(indexPath.row != 0){
    UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 1)];
    separatorLineView.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1.0];
    [cell.contentView addSubview:separatorLineView];
}
cell.pathDescriptionLbl.text = @"main text here";
Step *stp = [steps.stepsData objectAtIndex:indexPath.row];
NSString *txtDetails = @"Details text here";
cell.distanceLbl.text = @"Distance here";
return cell;
}

我觉得奇怪的是,行选择在iOS 7上完美运行,但在iOS 8上运行不正常。两种情况下都会填充数据。

我在这里做错了什么,或者我错过了什么。 在此先感谢帮助人员。

0 个答案:

没有答案