在我的項目中,我使用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;
}
我剛編輯我的代碼插入定製的第二小區。當我跑我的應用程序的第二個單元格(CellaIMG)不顯示! 你能告訴我我錯了嗎? – kAiN