【问题标题】:how to customise UITableView?如何自定义 UITableView?
【发布时间】:2012-09-08 12:56:34
【问题描述】:

如何添加如下截图所示的图像和文本?我已经在我的应用程序中使用导航控制器,所以将 UITableView 控制器作为主页中的新导航页面包含任何问题。

【问题讨论】:

    标签: ios ios4 xcode4 uitableview


    【解决方案1】:

    在配置UITableViewCell时,您可以将UIImageViewUILabel 添加到单元格contentView

    
    
        UITableViewCell *cell = ...;
    
        UIImageView *yourImageView = ...;
    
        UILabel *yourLabel = ...;
    
        [cell.contentView addSubview:yourImageView];
        [cell.contentView addSubview:yourLabel];
    
    

    【讨论】:

    • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    • 当然,这就是你要去的地方。
    【解决方案2】:

    我将继承 UITableView 单元并创建自己的单元MyCustomTableViewCell,其中包含 UIImageView 和 UILabel。

    然后您可以这样做以更新您的单元格以重用案例

    
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]
    
        MyCustomTableViewCell *myCell = (MyCustomTableViewCell)cell;
        myCell.label.text = newText;
        myCell.imageView.image = newImage;
    
        return cell;
    }
    

    【讨论】:

    猜你喜欢
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    相关资源
    最近更新 更多