大家好,我正在按照教程解释如何使用选定行
扩展单元格我已经实现了所有数组并正确返回数据但是当我选择单元格以扩展我的应用程序崩溃时会给我回复此错误
[PFObject sizeWithFont:constrainedToSize:lineBreakMode:]:无法识别的选择器发送到实例
断点我找到了点,但我不明白什么是错的...... 应用程序崩溃的点是
CGSize AltezzaLabel = [ [ ArrayforPost objectAtIndex : index ] sizew sizeWithFont : [ UIFont fontWithName : @ " Helvetica " size : 14.0f ] constrainedToSize : MAX lineBreakMode : NSLineBreakByCharWrapping ] ;
下面我提供了更好理解的实现
#import "FFTimeline.h"
#import "FFCustomCellTimelineSocial.h"
@interface FFTimeline ()
@end
@implementation FFTimeline
@synthesize ArrayforPost, NuovoArray;
@synthesize IsFlashPost;
- (void)viewDidLoad
{
[super viewDidLoad];
self.FFTableView.delegate = self;
self.FFTableView.dataSource = self;
CellaSelezionata = -1;
}
-(void)viewDidAppear:(BOOL)animated {
[self QueryForPost];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [ArrayforPost count];
}
-(void)QueryForPost {
PFQuery *QueryForFriend=[PFQuery queryWithClassName:FF_AMICIZIE_CLASS];
[QueryForFriend whereKey:FF_AMICIZIE_A_USER equalTo:[PFUser currentUser]];
[QueryForFriend whereKey:FF_AMICIZIE_STATO equalTo:@"Confermato"];
[QueryForFriend includeKey:FF_AMICIZIE_DA_USER];
PFQuery *QueryYES = [PFQuery queryWithClassName:FF_POST_CLASS];
[QueryYES whereKey:FF_POST_FLASH_POST_BOOLEANVALUE equalTo:[NSNumber numberWithBool:YES]];
[QueryYES whereKey:FF_POST_SCELTI equalTo:[PFUser currentUser]];
PFQuery *normalPostByFriends = [PFQuery queryWithClassName: FF_POST_CLASS];
[normalPostByFriends whereKey: FF_POST_FLASH_POST_BOOLEANVALUE equalTo: [NSNumber numberWithBool: NO]];
[normalPostByFriends whereKey: FF_POST_UTENTE matchesKey:FF_AMICIZIE_DA_USER inQuery:QueryForFriend];
PFQuery *normalPostByUser = [PFQuery queryWithClassName:FF_POST_CLASS];
[normalPostByUser whereKey:FF_POST_FLASH_POST_BOOLEANVALUE equalTo: [NSNumber numberWithBool: NO]];
[normalPostByUser whereKey:FF_POST_UTENTE equalTo: [PFUser currentUser]];
PFQuery *query = [PFQuery orQueryWithSubqueries:@[QueryYES,normalPostByFriends,normalPostByUser]];
[query includeKey:FF_POST_UTENTE];
[query orderByDescending:FF_CREATEDAT];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
if (!error) {
NSLog(@"%@", results);
ArrayforPost = [[NSMutableArray alloc] init];
for (PFObject *object in results) {
[ArrayforPost addObject:object];
}
[self.FFTableView reloadData];
}
}];
}
-(CGFloat)valoreAltezzaCella:(NSInteger)index {
CGSize MAX = CGSizeMake(230, 10000);
CGSize AltezzaLabel = [[ArrayforPost objectAtIndex:index] sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0f] constrainedToSize:MAX lineBreakMode:NSLineBreakByWordWrapping];
return AltezzaLabel.height;
}
- (FFCustomCellTimelineSocial *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FFCustomCellTimelineSocial *cell = (FFCustomCellTimelineSocial * )[self.FFTableView dequeueReusableCellWithIdentifier:@"CellPost"];
if (!cell) {
cell = [[FFCustomCellTimelineSocial alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellPost"];
}
if (CellaSelezionata == indexPath.row) {
CGFloat AltezzaLabel = [self valoreAltezzaCella: indexPath.row];
cell.FFTestoUtenteLabel.frame = CGRectMake(cell.FFTestoUtenteLabel.frame.origin.x, cell.FFTestoUtenteLabel.frame.origin.y, cell.FFTestoUtenteLabel.frame.size.width, AltezzaLabel);
} else {
cell.FFTestoUtenteLabel.frame = CGRectMake(cell.FFTestoUtenteLabel.frame.origin.x, cell.FFTestoUtenteLabel.frame.origin.y, cell.FFTestoUtenteLabel.frame.size.width, 65);
}
PFObject *ObjectPost = [ArrayforPost objectAtIndex:indexPath.row];
cell.FFTestoUtenteLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
NSString *text = [ObjectPost objectForKey:@"Testo"];
cell.FFTestoUtenteLabel.text = text;
[cell.FFTestoUtenteLabel setLineBreakMode:NSLineBreakByWordWrapping];
cell.backgroundCell.layer.masksToBounds = YES;
cell.backgroundCell.layer.cornerRadius = 5.0f;
cell.backgroundFotoProfilo.layer.masksToBounds = YES;
cell.backgroundFotoProfilo.layer.cornerRadius = 35.0f;
cell.FFImmagineUtente.layer.masksToBounds = YES;
cell.FFImmagineUtente.layer.cornerRadius = 30.0f;
cell.FFImmagineUtente.contentMode = UIViewContentModeScaleAspectFill;
PFObject *rowObject = [ArrayforPost objectAtIndex:indexPath.row];
if([[rowObject objectForKey:FF_POST_FLASH_POST_BOOLEANVALUE ] boolValue]) {
cell.FlashPostImg.image = [UIImage imageNamed:@"FFNotificaFlash"];
}
else {
cell.FlashPostImg.image = [UIImage imageNamed:@" "];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
if (CellaSelezionata == indexPath.row)
{
return [self valoreAltezzaCella:indexPath.row] + 10 * 2;
}
else {
return 65 + 10 * 2;
}
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self valoreAltezzaCella:indexPath.row] > 65) {
return indexPath;
} else {
return nil;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (CellaSelezionata == indexPath.row) {
CellaSelezionata = -1;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
if (CellaSelezionata >= 0) {
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:CellaSelezionata inSection:0];
CellaSelezionata = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
}
CellaSelezionata = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
答案 0 :(得分:1)
在valoreAltezzaCella:
方法中,[ArrayforPost objectAtIndex:index]
是PFObject
而不是NSString
,因此您无法对其sizeWithFont
进行申请。你可能想要类似的东西:
PFObject *objectPost = [ArrayforPost objectAtIndex:indexPath.row];
NSString *text = [objectPost objectForKey:@"Testo"];
CGSize altezzaLabel = [text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0f] constrainedToSize:MAX lineBreakMode:NSLineBreakByWordWrapping];