gpt4 book ai didi

ios - Storyboard中的自定义 UITableViewCell 不会加载

转载 作者:行者123 更新时间:2023-11-28 22:00:36 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题。我有一个 iOS 7.1 Storyboard应用程序,带有一个使用 Xcode 5 的 UITableViewController。我创建了一个 UITableViewCell 的子类,并将其设置为来自 IB 的单元格的类,还添加了一个细胞标识符。样式也设置为自定义。不过我还没有对这个子类做任何修改。它只有您在创建新类时获得的模板代码。

在 TableView Controller 中我有这段代码。只需设置数据源和委托(delegate)方法。

#import "TableViewController.h"
#import "TextFieldTableViewCell.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (void)viewDidLoad
{
[super viewDidLoad];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
TextFieldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"hello world";

return cell;
}

cellForRowAtIndexPath 中,我只是为单元格的 textLabel 属性设置了一个值。即使这样也没有显示出来。我仔细检查了标识符、样式和所有内容,它们都已设置。

我不知道为什么这不起作用。我还查看了一些关于此主题的在线教程,例如 this一个,但我拥有他们所描述的一切。

如果我遗漏了什么,有人可以告诉我吗?

我已将测试项目上传到我的 Dropbox here如果您想快速浏览一下。

最佳答案

找到了!您已经覆盖了 TextFieldTableViewCell 类的布局 subview ,并且没有在其中写入任何内容。

只需移除 layoutSubviews(暂时)即可。

更新:更好的解决方案;

- (void) layoutSubviews
{
[super layoutSubviews];
}

关于ios - Storyboard中的自定义 UITableViewCell 不会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com