【问题标题】:Customizing cells in nib so they are not static自定义 nib 中的单元格,使其不是静态的
【发布时间】:2014-12-08 17:13:58
【问题描述】:

我正在尝试自定义我的 UITableView 单元格,并且之前成功地完成了它而没有问题,但那是使用情节提要。现在我正在使用 xib 文件进行操作。出于某种原因,我无法将单元格更改为“自定义”单元格而不是静态的。即使像 numberofcells 方法这样简单的东西也不起作用,因为我无法自定义单元格。通常在情节提要中,我会“删除”或更改单元格,但我什至无法选择 nib 文件中的单元格!

我找不到任何方法来做到这一点,并且在这一点上使用情节提要并不是一个真正的选择。我的代码如下,谢谢!

#import "YouTubeViewController.h"
#import "YouTubeCell.h"

@interface YouTubeViewController ()

@end

@implementation YouTubeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 88;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {


    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *reuseIdentifier = @"YouTubeCell";     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"YouTubeCell" owner:nil options:nil] objectAtIndex:0];
    }

    //set up cell

    return cell;


//        [[cell authorName] setText:@"Collin Ruffenach"];
//        [[cell articleName] setText:@”Test Article 1″];
//        [[cell date] setText:@”May 5th, 2009″];
//        [[cell imageView] setImage:[UIImage imageNamed:@"1.png"]];



}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

【问题讨论】:

  • 我很困惑——什么是“静态”单元格?
  • Prototype Cells in a nib instead of a storyboard 的可能重复项 - 您不能像在情节提要中那样在 nib 的 tableview 中编辑原型单元格 - 您必须定义一个额外的 nib 并注册它
  • @Paulw11 您能否详细说明“定义一个额外的 nib 并注册它”是什么意思?
  • 你看到我链接的问题的接受答案了吗?

标签: ios objective-c xcode uitableview


【解决方案1】:

事实证明,我需要做的只是通过控制从 uitableview 到“文件所有者”的点击来设置委托和数据源。之后一切正常!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多