Я пытаюсь сделать фид элемента с UITableView
и некоторыми объектами JSON, , но когда я попробую заполнить экземпляр моей пользовательской ячейки данными JSON, то UILabel
s не будет изменить их текст.UITableViewCells не принимает пользовательское значение
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;
}
}
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
+ (id) InitPost {
// init new feed item
return [[self alloc]init];
}
были получить следующее сообщение об ошибке:
-[__NSCFString text]: unrecognized selector sent to instance
Что я делаю неправильно?
Где находится ваш код, который показывает настройки ячеек 'UILabels' с новым текстом? Добавьте недостающий код в метод 'tableView: cellForRowAtIndexPath:'. –
Вам необходимо вызвать 'reloadData' в вашей таблице после загрузки данных – Paulw11
сейчас нет. потому что я пытаюсь сделать это в цикле for в методе 'viewdidload' @RoboticCat –