gpt4 book ai didi

iOS 不符合键值编码的 uitableview

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:22 27 4
gpt4 key购买 nike

我有一个 UIViewController,里面有一个 UITableView。 UIViewController 不是 UITableViewController,因为 View 上还有其他东西。如果我不连接任何 socket ,空表会和其他东西一起出现在 View 中,没有错误。如果我将 UIViewController 的 socket 连接到 UITableView,我会收到以下错误:

'[<UIViewController 0x748a420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableStories.'

如果我还连接数据源并将 UITableView 的导出委托(delegate)给 UIViewController,我会得到同样的错误。这是 View Controller 的 .h

#import <UIKit/UIKit.h>

@interface IntroViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>


@property (nonatomic, weak) IBOutlet UITableView *tableStories;
@property (nonatomic, strong) NSManagedObjectContext* managedObjectContext;
@property (nonatomic, strong) NSArray *stories;

这是.m

@implementation IntroViewController

@synthesize tableStories;
@synthesize stories;
@synthesize managedObjectContext;


- (void)viewDidLoad
{
[super viewDidLoad];

tableStories.delegate = self;
tableStories.dataSource = self;

managedObjectContext = ((ReadMeAppDelegate *)[UIApplication sharedApplication].delegate).managedObjectContext;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"RMStory" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.stories = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [stories count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
RMStory *thisStory = [stories objectAtIndex:indexPath.row];
cell.textLabel.text = thisStory.title;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", thisStory.author];

return cell;
}

这可能与我的 Core Data 命令有关,但我一直在尝试堆栈中提到的其他解决方案来解决此错误,但到目前为止没有任何效果。 :-/

此外,我从另一个应用程序导入了 Storyboard,所以这可能会造成一些麻烦。

最佳答案

我想通了。我在调试器输出的一开始就收到一个错误

Unknown class IntroViewController in Interface Builder file.

我在 StackExchange 上查找了错误并找到了答案 here这是Matthew这给出了我使用的答案。我必须将 IntroViewController 添加到编译源列表中。我不确定这意味着什么,或者为什么它没有阻止程序在没有 TableView 的情况下运行,但现在它可以工作了。感谢 StackExchange!!

关于iOS 不符合键值编码的 uitableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12850474/

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