gpt4 book ai didi

ios - 非自定义 uitableviewcell 样式被忽略

转载 作者:行者123 更新时间:2023-11-28 22:14:20 26 4
gpt4 key购买 nike

我没有做任何棘手的事情。使用 Apple 提供的默认模板中的标准 TableView Controller,我只是将 Style 更改为“Subtitle”。更改反射(reflect)在 Storyboard中,但它在模拟器中仍然是基本的。

项目的唯一修改是:- 我将导航 Controller 嵌入到选项卡 Controller 中- 我在表格 View 中插入了一个搜索栏和搜索显示 Controller - 我添加了一个对象来从网站导入 XML 数据

这个项目是另一个项目的基本(精简)版本,该项目现在正在生产中,但只使用 NSDictionary 而不是核心数据。这个新项目是我学习护理数据的尝试,但我无法解决这个讨厌的问题。

我在没有更新代码的情况下将我的单元格标识符从“Cell”更改为“aeJobCell”,但应用程序仍然成功运行。它没有提示没有“Cell”的单元格标识符。然后我在我的代码中进行了测试,以确保它使用了正确的标识符。标签设置正确。数据显示在单元格中,但我看不到副标题。

抱歉,我没有足够的声誉来发布图片。我将粘贴代码并尽可能描述我所拥有的内容。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
ImportedAEJob *aeJob = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell = [tableView dequeueReusableCellWithIdentifier:@"aeJobCell"];
aeJob = [self.searchResults objectAtIndex:indexPath.row];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"aeJobCell" forIndexPath:indexPath];
aeJob = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"aeJobCell"];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
//[self configureCell:cell atIndexPath:indexPath];
[self configureCell:cell forAEJob:aeJob];
return cell;
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
// NSString *aJobNo = [[object valueForKey:@"aeJobNo"] description];
// NSString *aDeliverTo = [[object valueForKey:@"aeDeliverTo"] description];
cell.textLabel.text = [[object valueForKey:@"aeJobNo"] description];
cell.detailTextLabel.text = [[object valueForKey:@"aeDeliverTo"] description];
}

- (void)configureCell:(UITableViewCell *)cell forAEJob:(ImportedAEJob *)aeJob
{
// NSString *aJobNo = aeJob.aeJobNo;
// NSString *aDeliverTo = aeJob.aeDeliverTo;
cell.textLabel.text = aeJob.aeJobNo;
cell.detailTextLabel.text = aeJob.aeDeliverTo;
}

我重置了内容和设置,删除了衍生数据,重新启动了我的电脑,拍了拍我的肚子并揉了揉我的头(反之亦然)。我在这个论坛上阅读了十几篇帖子,但没有一篇讨论这个具体问题。大多数关于单元格未正确显示的帖子都涉及自定义单元格,但我没有使用自定义单元格。我什至不知道该怎么做。

在这个问题上我已经达到了能力极限。请帮忙。

<----- EDIT ------->

以下是我对应用委托(delegate)所做的更改,以防有帮助:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
rushMasterViewController *controller = (rushMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
} else {
UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex: 0];

//UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
rushMasterViewController *controller = (rushMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
return YES;
}

最佳答案

副标题没有出现的原因是你用这行注册了类(class):

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"aeJobCell"];

当您使用来自 Storyboard的单元格时,无论是 UITableViewCell 还是您自己的自定义类,您都不应该注册任何内容。如果单元格仅在代码中定义,则注册类,如果它是在 xib 文件中创建的,则注册 nib。

关于ios - 非自定义 uitableviewcell 样式被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22106007/

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