gpt4 book ai didi

ios - 所选行应用程序是否崩溃

转载 作者:行者123 更新时间:2023-11-29 03:29:05 25 4
gpt4 key购买 nike

大家好,我正在学习一个教程,其中解释了如何扩展所选行的单元格

我已经实现了所有数组并正确返回数据,但是当我选择单元格来扩展我的应用程序崩溃时,我返回了此错误

[ PFObject sizeWithFont : constrainedToSize : lineBreakMode :]: unrecognized selector sent to instance

使用断点我找到了重点,但我不明白出了什么问题......应用程序崩溃的点是

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];
}

最佳答案

在您的 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];

关于ios - 所选行应用程序是否崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20058416/

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