Ios UITableViewCells不';不接受自定义值

Ios UITableViewCells不';不接受自定义值,ios,objective-c,json,uitableview,Ios,Objective C,Json,Uitableview,我正在尝试使用UITableView和一些JSON对象制作一个项目提要, 但是当我尝试用JSON数据填充自定义单元格的实例时,UILabels不会更改它们的文本 JSON已经过测试,可以正常工作。它通过循环并创建适当数量的行。但是文本不会更改为JSON文件中的文本 这是我的密码: feed.m - (void)viewDidLoad { [super viewDidLoad]; NSURL *FeedURL = [NSURL URLWithString:@"http://www

我正在尝试使用
UITableView
和一些JSON对象制作一个项目提要, 但是当我尝试用JSON数据填充自定义单元格的实例时,
UILabel
s不会更改它们的文本

JSON已经过测试,可以正常工作。它通过循环并创建适当数量的行。但是文本不会更改为JSON文件中的文本

这是我的密码:

feed.m

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *FeedURL = [NSURL URLWithString:@"http://www.personeelsapp.jordivanderhek.com/company/bijcasper/nieuws.json"];
    NSData *jsonData = [NSData dataWithContentsOfURL:FeedURL];
    NSError *error = nil;
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

    NSLog(@"%@", dataDictionary);

    self.posts = [NSMutableArray array];
    PostsArray = [dataDictionary objectForKey:@"feed"];

    for (NSDictionary *bpdDictionary in PostsArray) {
        // make new post object
        FeedPosts *posts = [FeedPosts InitPost];
        NSLog(@"feed check %@" ,[bpdDictionary objectForKey:@"name"]);
        posts.postTitle = [bpdDictionary objectForKey:@"name"];
        posts.postProfilepic = [bpdDictionary objectForKey:@"profilePic"];
        posts.postDatum = [bpdDictionary objectForKey:@"timeStamp"];
        posts.postMessage = [bpdDictionary objectForKey:@"status"];
        posts.postImage = [bpdDictionary objectForKey:@"image"];
        [self.posts addObject:posts];
    }
}

 […]

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Cellindentifier = @"PostCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cellindentifier forIndexPath:indexPath];

    // Configure the cell...
    FeedPosts *posts = [self.posts objectAtIndex:indexPath.row];

   cell.postTitle.text = @"test title";
   cell.postDatum.text = posts.postDatum.text;
   cell.postMessage.text = posts.postMessage.text;
return cell;
}
}
+ (id) InitPost {
    // init new feed item
    return [[self alloc]init];
}
FeedPosts.h

@property (strong, nonatomic) IBOutlet UILabel *postTitle;
@property (strong, nonatomic) IBOutlet UILabel *postMessage;
@property (strong, nonatomic) IBOutlet UIImageView *postImage;
@property (strong, nonatomic) IBOutlet UIImageView *postProfilepic;
@property (strong, nonatomic) IBOutlet UILabel *postDatum;

// designated init
+ (id) InitPost;
FeedPosts.m

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *FeedURL = [NSURL URLWithString:@"http://www.personeelsapp.jordivanderhek.com/company/bijcasper/nieuws.json"];
    NSData *jsonData = [NSData dataWithContentsOfURL:FeedURL];
    NSError *error = nil;
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

    NSLog(@"%@", dataDictionary);

    self.posts = [NSMutableArray array];
    PostsArray = [dataDictionary objectForKey:@"feed"];

    for (NSDictionary *bpdDictionary in PostsArray) {
        // make new post object
        FeedPosts *posts = [FeedPosts InitPost];
        NSLog(@"feed check %@" ,[bpdDictionary objectForKey:@"name"]);
        posts.postTitle = [bpdDictionary objectForKey:@"name"];
        posts.postProfilepic = [bpdDictionary objectForKey:@"profilePic"];
        posts.postDatum = [bpdDictionary objectForKey:@"timeStamp"];
        posts.postMessage = [bpdDictionary objectForKey:@"status"];
        posts.postImage = [bpdDictionary objectForKey:@"image"];
        [self.posts addObject:posts];
    }
}

 […]

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Cellindentifier = @"PostCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cellindentifier forIndexPath:indexPath];

    // Configure the cell...
    FeedPosts *posts = [self.posts objectAtIndex:indexPath.row];

   cell.postTitle.text = @"test title";
   cell.postDatum.text = posts.postDatum.text;
   cell.postMessage.text = posts.postMessage.text;
return cell;
}
}
+ (id) InitPost {
    // init new feed item
    return [[self alloc]init];
}
已收到以下错误:

-[__NSCFString text]: unrecognized selector sent to instance
我做错了什么?

您在feedpost中声明了几个UILabel

在以下代码中,将NSString(文本)指定给label对象:

FeedPosts *posts = [FeedPosts InitPost];
NSLog(@"feed check %@" ,[bpdDictionary objectForKey:@"name"]);
posts.postTitle = [bpdDictionary objectForKey:@"name"];
相反,您应该设置这些标签的文本:

posts.postTitle.text = [bpdDictionary objectForKey:@"name"];

postMessage
postdatam

显示新文本单元格设置的代码在哪里?请将缺少的代码添加到
tableView:cellforrowatinexpath:
方法中。加载数据后,需要在表上调用
reloadData
,因为现在没有任何代码。因为我试图在
viewdidload
方法中的for循环中执行此操作@RoboticCat@JordivanderHek嗯?您需要在
cellforrowatinexpath
方法中创建、设置并返回一个单元格。显示该代码。@rmaddy我无法在cellForRowAtIndexPath中重新定义任何内容“单元格”没有任何可用于链接到我的标签的属性