在我的项目中,我正在使用Parse.com在表格视图中检索数据。
我的Tableview有一个名为FFCustomCell1的自定义单元格,里面有2个标签:
第一个标签包含我的应用的名字和姓氏 第二个标签包含我的应用程序的注册日期。
现在我的问题是我的应用程序的用户并不总是将他的照片放在他的数据中然后我需要创建第二个自定义单元格,其中包含与FFCustomCell1完全相同的数据,添加一个带有用户照片的ImageView
简而言之,我需要表视图显示单元格FFCustomCell1如果没有图片或用户的时间但是如果用户输入了他的图片我需要表格视图显示FFCustomCell2
现在根据您在此处的代码,您认为实现目标的最佳途径是什么?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [ArrayforPost count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *IdentificazioneCella = @"CellPost";
static NSString *IdentificazioneCellaIMG = @"CellIMG";
FFCustomCellTimelineSocial *Cella = nil;
FFCustomCellWithImage *CellaIMG = nil;
// FIRST CUSTOM CELL
Cella = (FFCustomCellTimelineSocial * )[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCella];
Cella.backgroundCell.layer.cornerRadius = 2.0f;
Cella.backgroundCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
Cella.backgroundCell.layer.borderWidth = 1.0f;
Cella.backgroundCell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Cella.BackgroundText.layer.cornerRadius = 2.0f;
Cella.BackgroundText.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
Cella.BackgroundText.layer.borderWidth = 0.0f;
Cella.BackgroundText.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Cella.TimeBackground.layer.cornerRadius = 2.0f;
Cella.TimeBackground.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
Cella.TimeBackground.layer.borderWidth = 1.0f;
Cella.ViewTestataCell.layer.cornerRadius = 2.0f;
Cella.ViewTestataCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
Cella.ViewTestataCell.layer.borderWidth = 1.0f;
Cella.FFImmagineUtente.layer.masksToBounds = YES;
Cella.FFImmagineUtente.layer.cornerRadius = 20.0f;
Cella.FFImmagineUtente.contentMode = UIViewContentModeScaleAspectFill;
PFObject *ObjectPost = [ArrayforPost objectAtIndex:indexPath.row];
Cella.FFTestoUtenteLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
NSString *text = [ObjectPost objectForKey:@"Testo"];
Cella.FFTestoUtenteLabel.text = text;
[Cella.FFTestoUtenteLabel setLineBreakMode:NSLineBreakByTruncatingTail];
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd MMM"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
Cella.DataCorrente.text = dateString;
NSString *NomeUser = [[ObjectPost objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_NOMECOGNOME];
Cella.FFNomeUtenteLabel.text = NomeUser;
NSString *ImmagineUtente = [[ObjectPost objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_FOTOPROFILO];
Cella.FFImmagineUtente.file = (PFFile *)ImmagineUtente;
[Cella.FFImmagineUtente loadInBackground];
if (CellaSelezionata == indexPath.row) {
CGFloat AltezzaLabel = [self valoreAltezzaCella: indexPath.row];
Cella.FFTestoUtenteLabel.frame = CGRectMake(Cella.FFTestoUtenteLabel.frame.origin.x, Cella.FFTestoUtenteLabel.frame.origin.y, Cella.FFTestoUtenteLabel.frame.size.width, AltezzaLabel); }
else {
Cella.FFTestoUtenteLabel.frame = CGRectMake(Cella.FFTestoUtenteLabel.frame.origin.x, Cella.FFTestoUtenteLabel.frame.origin.y, Cella.FFTestoUtenteLabel.frame.size.width, 55);
}
PFObject *rowObject = [ArrayforPost objectAtIndex:indexPath.row];
if([[rowObject objectForKey:FF_POST_FLASH_POST_BOOLEANVALUE ] boolValue]) {
Cella.FlashPostImg.image = [UIImage imageNamed:@"FFNotificaFlash"];
}
else {
Cella.FlashPostImg.image = [UIImage imageNamed:@" "]; }
return Cella;
// SECOND CUSTOM CELL
PFObject *Immagine = [self.ArrayForPhoto objectAtIndex:indexPath.row];
if ([Immagine objectForKey:FF_POST_IMMAGINE]) {
CellaIMG = (FFCustomCellWithImage * )[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCellaIMG];
NSString *FotoPostSocial = [Immagine objectForKey:FF_POST_IMMAGINE];
CellaIMG.FotoPost.file = (PFFile *)FotoPostSocial;
[ CellaIMG.FotoPost loadInBackground];
}
return CellaIMG;
}
答案 0 :(得分:1)
我不能对你的问题发表评论,所以我写这个作为答案。以下是我在你的情况下可能会做的事情。