zoukankan      html  css  js  c++  java
  • xib方式定义tableviewcell步骤以及需要注意的点

    @interface ContentsTableViewCell()
    @property (weak, nonatomic) IBOutlet UIImageView *headermag;
    @property (weak, nonatomic) IBOutlet UILabel *namelabel;
    @property (weak, nonatomic) IBOutlet UILabel *citylabe;
    @property (weak, nonatomic) IBOutlet UILabel *looklabel;
    @property (weak, nonatomic) IBOutlet UIImageView *bigmag;
    ******************这里使用xib拖拽的
    @end
    
    @implementation ContentsTableViewCell
    
    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
            
        }return self;
    }
    - (void)awakeFromNib {
        [super awakeFromNib];
        // Initialization code
    }

    2.。。。。重载如下方法也无法达到修改效果

    //-(void)layoutSubviews

    //{

    //    [self layoutSubviews];

    //    [self UpdateUI];

    //}

    }

    3.。。。。。。。。3.这个方法最好 对视图的修改方法可以解决 - (void)drawRect:(CGRect)rect { [self updateUI]; }
    // 更新视图的方法 这个视图要再哪里调用 我们这里分析下1.2.3 - (void)updateUI { _headermag.layer.cornerRadius = 20; _headermag.layer.masksToBounds = YES; _looklabel.numberOfLines = 2; _looklabel.textAlignment = NSTextAlignmentRight; } - (void)setContentsmodel:(ContentsModel *)contentsmodel {
    1.。。。。。。1.尝试过在此次对里面的子视图进行修改,但初次显示的内容尺寸无法修改,当这个cell被重用时可以达到修改效果,也深度在此时通过定时器延时进行修改,可解决,可有时会有延时的效果,不完美... 在这里就赋值就好了 但是对子视图控件有需要修改的地方这里不是最优的 _contentsmodel = contentsmodel; [_headermag sd_setImageWithURL:[NSURL URLWithString:_contentsmodel.creator.portrait] placeholderImage:[UIImage imageNamed:@"tab_me_p"]]; _namelabel.text = _contentsmodel.creator.nick; _citylabe.text = _contentsmodel.city; [_bigmag sd_setImageWithURL:[NSURL URLWithString:_contentsmodel.creator.portrait] placeholderImage:[UIImage imageNamed:@"tab_me_p"]]; }

     在controller里面可以这么实现

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        FavoriteItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FavoriteItemCell"];
        if (cell == nil)
        {
            cell = (FavoriteItemCell *)[[NSBundle mainBundle] loadNibNamed:@"FavoriteCell" owner:self options:nil][0];
        }
        cell.model = _arrayOfData[indexPath.section];
    
        
        return cell;
    }
    
  • 相关阅读:
    在WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,
    Sqlserver 2008 评估版本到期,Sqlserver 2008试用期已过,解决方案.
    C#防止WebBrowser在新窗口中打开链接页面
    c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
    屏蔽右键代码(防止网页恶意复制)
    SEO优化中的div+css命名规则
    photoshop CS不能打字,出现死机等现象的解决办法!!
    带关闭功能的漂浮图片代码
    VS2008连接SQL2005问题,老连接不上。
    WinForm中获取鼠标当前位置
  • 原文地址:https://www.cnblogs.com/wangxiaoqi/p/6430889.html
Copyright © 2011-2022 走看看