美文网首页iOSiOS Developer程序员
 第一次在简书上写文章

 第一次在简书上写文章

作者: 码农冰冰 | 来源:发表于2016-11-18 11:35 被阅读204次
    42C527D6-90B0-4858-8EE5-6C9005EC3226.png 32358BF9-7A7D-4FFD-8D70-46CB4F129D2B.png

    代码实现:

    • cellForRowAtIndexPath方法:
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        NSLog(@"11111111111111");
    
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
            cell.backgroundColor =[UIColor clearColor];
            UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
            selectedBackgroundView.backgroundColor = [UIColor whiteColor];
            cell.selectedBackgroundView = selectedBackgroundView;   
            // 左侧示意条
            UIView *liner = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 2, 40)];
            liner.backgroundColor = [UIColor orangeColor];
            [selectedBackgroundView addSubview:liner];
        }
        cell.textLabel.text=[NSString stringWithFormat:@"第%ld个",indexPath.row];
            return cell; 
    }
    
    • 代理方法:
    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{    
        NSLog(@"22222222222222");
        if (_isRelate==YES) {
                [tableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        }
    }
    
    - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0){
        NSLog(@"33333333333333");
        _isRelate=NO;
    }
    

    当然也有很多其他的实现方式就不多做介绍了。

    相关文章

      网友评论

        本文标题: 第一次在简书上写文章

        本文链接:https://www.haomeiwen.com/subject/nhkjpttx.html