2013-11-22 217 views
0

我聲明在我的應用程序中,我使用Parse.com來存儲和管理數據。當我運行應用程序時,我的TableView崩潰了應用程序

在我的tableview中,我引入了兩個不同的自定義單元格。如果有圖像則顯示A,如果圖像不存在則顯示另一隻手。

現在一切似乎工作,但是當我去讓應用程序運行泰伯維崩潰報告這個錯誤:

2013年11月22日15:36:34.256 Unigo網站[17186:70B] 在 - [UITableView _configureCellForDisplay:forIndexPath:],/ SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:62 46 **

您能解釋我錯在哪?

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.FFTableView.delegate = self; 
    self.FFTableView.dataSource = self; 

    CellaSelezionata = -1; 
} 

-(void)viewDidAppear:(BOOL)animated { 
    [self QueryForPost]; 
} 

-(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) { 
      ArrayforPost = [[NSMutableArray alloc] init]; 
      for (PFObject *object in results) { 
       [ArrayforPost addObject:object]; 
      } 
      [self.FFTableView reloadData]; 
     } 
    }];  

} 


-(CGFloat)valoreAltezzaCella:(NSInteger)index { 
    PFObject *objectPost = [ArrayforPost objectAtIndex:index]; 
    NSString *text = [objectPost objectForKey:@"Testo"]; 
    CGSize MAX = CGSizeMake(230, 10000); 
    UIFont *FONT = [UIFont systemFontOfSize:14]; 
    CGSize altezzaLabel = [text boundingRectWithSize:MAX options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT }context:nil].size; 
    return altezzaLabel.height; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [ArrayforPost count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    PFObject *ObjectPost = [ArrayforPost objectAtIndex:indexPath.row]; 

    // FIRST CUSTOM CELL 
if (![ObjectPost objectForKey:FF_POST_IMMAGINE]) { 

    static NSString *IdentificazioneCella = @"CellPost"; 

FFCustomCellTimelineSocial * Cella = (FFCustomCellTimelineSocial *)[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCella]; 


    if (Cella == nil) { 
     Cella = [[FFCustomCellTimelineSocial alloc] 
        initWithStyle:UITableViewCellStyleSubtitle 
        reuseIdentifier: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; 

    Cella.FFTestoUtenteLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f]; 
    NSString *text = [ObjectPost objectForKey:FF_POST_TEXT]; 
    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; 
} 


else { 

     // SECOND CUSTOM CELL 
    static NSString *IdentificazioneCellaIMG = @"CellIMG"; 

    FFCustomCellWithImage * CellaIMG = (FFCustomCellWithImage *)[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCellaIMG]; 

CellaIMG = (FFCustomCellWithImage *)[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCellaIMG]; 

    if (CellaIMG == nil) { 
     CellaIMG = [[FFCustomCellWithImage alloc] 
        initWithStyle:UITableViewCellStyleSubtitle 
        reuseIdentifier:IdentificazioneCellaIMG ]; 
    } 

    NSString *FotoPostSocial = [ObjectPost objectForKey:FF_POST_IMMAGINE]; 
    CellaIMG.FotoPost.file = (PFFile *)FotoPostSocial; 
    [CellaIMG.FotoPost loadInBackground]; 

    CellaIMG.backgroundCell.layer.cornerRadius = 2.0f; 
    CellaIMG.backgroundCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor; 
    CellaIMG.backgroundCell.layer.borderWidth = 1.0f; 
    CellaIMG.backgroundCell.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
     CellaIMG.TimeBackground.layer.cornerRadius = 2.0f; 
    CellaIMG.TimeBackground.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor; 
    CellaIMG.TimeBackground.layer.borderWidth = 1.0f; 
    CellaIMG.ViewTestataCell.layer.cornerRadius = 2.0f; 
    CellaIMG.ViewTestataCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor; 
    CellaIMG.ViewTestataCell.layer.borderWidth = 1.0f; 
    CellaIMG.FotoProfilo.layer.masksToBounds = YES; 
    CellaIMG.FotoProfilo.layer.cornerRadius = 20.0f; 
    CellaIMG.FotoProfilo.contentMode = UIViewContentModeScaleAspectFill; 

    CellaIMG.TestoPost.font = [UIFont fontWithName:@"Helvetica" size:14.0f]; 
    NSString *text = [ObjectPost objectForKey:FF_POST_TEXT]; 
    CellaIMG.TestoPost.text = text; 
    [CellaIMG.TestoPost setLineBreakMode:NSLineBreakByTruncatingTail]; 

    NSDate *currDate = [NSDate date]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
    [dateFormatter setDateFormat:@"dd MMM"]; 
    NSString *dateString = [dateFormatter stringFromDate:currDate]; 
    CellaIMG.DataPost.text = dateString; 

    NSString *NomeUser = [[ObjectPost objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_NOMECOGNOME]; 
    CellaIMG.NomeUtente.text = NomeUser; 

    NSString *ImmagineUtente = [[ObjectPost objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_FOTOPROFILO]; 
    CellaIMG.FotoProfilo.file = (PFFile *)ImmagineUtente; 
    [CellaIMG.FotoProfilo loadInBackground]; 

    if (CellaSelezionata == indexPath.row) { 
     CGFloat AltezzaLabel = [self valoreAltezzaCella: indexPath.row]; 
     CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, AltezzaLabel); 
    } 
    else { 

     CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, 75); 
    } 

    return CellaIMG; 

    } 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { 
    if (CellaSelezionata == indexPath.row) { 

     //SPAZIO INTERNO VERSO IL BASSO QUANDO APRI LA CELLA 
     return [self valoreAltezzaCella:indexPath.row] + 60 * 2; 
    } 

    else { 

     //GRANDEZZA CELLA PRIMA DI APRIRE 
     return 155 + 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]; 
} 

enter image description here

+0

您可以發佈它顯示在崩潰完整的郵件?在某些情況下,很可能你會返回一個零而不是單元格。 –

+0

您忽略了錯誤消息的重要部分。更新你的問題(不要在評論中發佈)其餘的錯誤。 – rmaddy

回答

1
dequeueReusableCellWithIdentifier - can return you nil 

您需要檢查並創建一個細胞,如果出現這種情況:

FFCustomCellTimelineSocial * Cella = (FFCustomCellTimelineSocial *)[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCella]; 

if (Cella == nil) { 
    Cella = [[[FFCustomCellTimelineSocial alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:CellIdentifier] autorelease]; 
} 
+0

我根據你的建議編輯我的代碼..現在它的工作!該應用程序不會崩潰,但第二個單元格不顯示......不顯示第二個單元格的內容,您只能看到白色單元格,但沒有內容......我哪裏出錯了? – kAiN

+0

你期望它是什麼類型的細胞? –

+0

我插入了Tableview的圖像,讓你更好地理解......正如你所看到的,第一個單元格完美地顯示出來,然而第二個單元格完全是白色的......第二個單元格的內容與第一個單元格的內容完全相同比那只有除了第一個單元格的內容還有一個UIImageView – kAiN

相關問題