{username =; ,email =;
我正在开发一对多关系博客应用。我已将所有内容编码为自定义TableViewCell,包括UILabel的nameLabel(显示博客帖子的作者),timeLabel(显示createdAt日期/字符串的查询结果)和textContent(显示实际post也是来自Parse Class对象的查询)。一切都很完美...除了名称标签返回
显然,此返回值大于自定义单元格中显示的UILabel。请帮我解决这个问题,因为我想做的就是查询我的"作者" object是指向我的_User类的指针,其中PFUser数据存储在Parse上。此外,如果我需要解释更多,请询问,我会尽我所能,因为我是一个新的开发人员。谢谢!
哇...如果我有10个声望,我可以发布快照,这样每个人都会知道如何回答我。![ALPostsQueryTableViewController.m file:][2]
#import "ALPostsQueryTableViewController.h"
#import "ALPostsTableViewCell.h"
@interface ALPostsQueryTableViewController ()
@end
@implementation ALPostsQueryTableViewController
- (id)initWithCoder:(NSCoder *)aCoder {
self = [super initWithCoder:aCoder];
if (self) {
// Customize the table
// The className to query on
self.parseClassName = @"Post";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 25;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
// If no objects are loaded in memory, we look to the cache
// first to fill the table and then subsequently do a query
// against the network.
if ([self.objects count] == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:@"createdAt"];
[query includeKey:@"author"];
return query;
}
#pragma mark - Table view data source
- (ALPostsTableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
ALPostsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ALPostsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.textView.text = [object objectForKey:@"textContent"];
cell.nameLabel.text = [NSString stringWithFormat:@"%@",
[object objectForKey:@"author"]];
NSLog(@"Username is %@", [object objectForKey:@"author"]);
NSDate *created = [object createdAt];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
cell.timeLabel.text = [NSString stringWithFormat:@"%@", [dateFormat stringFromDate:created]];
return cell;
}
@end
答案 0 :(得分:0)
发生的事情是返回的对象具有使用includeKey急切获取的关系。
获取他们的财产的方式就是你如何做,但你需要更进一步,并询问相关的"作者"的内部。对象(恰好是PFUser
)
// replace your code that sets the nameLabel text with this code...
PFUser *author = [object objectForKey:@"author"];
NSString *authorsUsername = author.username;
cell.nameLabel.text = authorsUsername;