2012-01-22 7 views
2

私は、UITableViewとメソッドreloadDataにいくつか問題があります。最新のアイテムが最初の位置に表示されますので、データベース内の最後の情報に更新ボタンの上にクリックしたときに、私はのtableViewを更新していますuitableviewリロードデータキャッシュ?

は降順命じました。

私のテーブルビュー内のすべてのセルには、カスタムラベルとuiimageviewsで満たされています。

うーん...事は、私が更新ボタンと、新しいデータが見つかったことを押したときに、最初の5行(ディスプレイに表示されているものがある)に更新されていませんが、次の行がないということです。しかし、最初の5行のいずれかを押すと、新しいデータでtableView:didSelectRowAtIndexPath:メソッドが正しく呼び出されます。

ので、問題は最初の5行のテーブルビューの「視覚的な」コンテンツが更新されていないことです。

誰でも私にこれを手伝うことができますか?

ありがとうございます!

コード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = [ NSString stringWithFormat: @"%d:%d", [ indexPath indexAtPosition: 0 ], [ indexPath indexAtPosition:1 ]]; 

    UITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease]; 

     // Configure the cell... 
     cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
     Activity *activity = [[self.activities valueForKey:[[[self.activities allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 
     [email protected]""; 
     //Mostramos el nombre 
     UILabel *label= [[UILabel alloc] initWithFrame:CGRectMake(60, -5, 200, 34)]; 
     label.text = [activity name]; 
     label.font = [UIFont boldSystemFontOfSize:17]; 
     label.backgroundColor = [UIColor clearColor]; 
     [cell addSubview:label]; 
     [label release]; 

     //Mostramos la imagen 
     UIImageView *leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 3, 50, 50)]; 
     [cell addSubview:leftImage]; 


     UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(60, 25, 200, 38)]; 
     textView.editable = NO; 
     textView.backgroundColor = [UIColor clearColor]; 
     textView.textColor = [UIColor grayColor]; 
     textView.font = [UIFont systemFontOfSize:12.0]; 
     textView.contentInset = UIEdgeInsetsMake(-8,-8,0,0); 
     textView.userInteractionEnabled=NO; 
     [cell addSubview:textView]; 

     switch ([activity notType]) { 
      case 0: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"requestPUSH",@""),[activity name]]; 
       leftImage.image = [UIImage imageNamed:@"ios.png"]; 
       break; 
      case 1: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"MPCreatedPushString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"mpNew.png"]; 
       break; 
      case 2: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"MPUpdatedPushString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"mpUpdated.png"]; 
       break; 
      case 3: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"MPDeletedPushString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"ios.png"]; 
       break; 
      case 4: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"MPGuestConfirmationPUSHString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"attend.png"]; 
       break; 
      case 5: 
       if ([[activity message] isEqualToString:@"noData"]) { 
        textView.text = [NSString stringWithFormat:NSLocalizedString(@"ShoutPushString",@""),[activity name]]; 
       }else{ 
        textView.text = [NSString stringWithFormat:NSLocalizedString(@"ShoutPushStringWithData",@""),[activity name], [activity message]]; 
       } 
       UIImage *contactImage = [UIImage imageWithData:[[activity person] pic]]; 
       if (contactImage!=nil) { 
        leftImage.image = contactImage; 
        //redondeamos bordes 
        CALayer * l = [leftImage layer]; 
        [l setMasksToBounds:YES]; 
        [l setCornerRadius:5.0]; 
       }else{ 
        leftImage.image = [UIImage imageNamed:@"ios.png"]; 
       } 
       break; 
      case 6: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"CheckinPushString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"ios.png"]; 
       break; 
      case 7: 
       textView.text = [NSString stringWithFormat:NSLocalizedString(@"MPGuestRejectionPUSHString",@""),[activity name],[activity nameItem]]; 
       leftImage.image = [UIImage imageNamed:@"reject.png"]; 
       break; 
      default: 
       break; 
     } 
     [leftImage release]; 
     [textView release]; 


     //Mostrar fecha 
     double timestamp = [[activity datetime] doubleValue]/1000; 
     NSString *dateShow; 

     NSDate *datetime = [NSDate dateWithTimeIntervalSince1970:timestamp]; 
     NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
     [dateFormat setDateFormat:@"HH:mm"]; 
     dateShow=[dateFormat stringFromDate:datetime]; 

     UILabel *label2= [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 70, 20)]; 
     label2.text = dateShow; 
     label2.textAlignment = UITextAlignmentRight; 
     label2.font = [UIFont systemFontOfSize:12]; 
     label2.backgroundColor = [UIColor clearColor]; 
     label2.textColor = [UIColor blueColor]; 
     [cell addSubview:label2]; 
     [label2 release]; 

    } 

    return cell; 
} 
+0

たぶん、あなたはあなたのセルの作成コードを投稿する必要がありますか? – Tom

+0

コードが追加されました、それほどではありません、hehe!ありがとう – Ibai

答えて

1

はうーん、そうあなたは、各セルに固有のセル識別子を与えます。それには理由がありますか? ほとんどの人が(すでにコンテンツが含まれている読んで)あなたがテーブルをリロードすると、このコールUITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier]; はあなたに再利用するセルを取得します

... iOSのテーブルの彼らの誤解がそのように見てパッチを適用してみてください。

しかし、あなたのコードは唯一の「新鮮な」細胞のために働く:if (cell == nil) { 、あなただけのような場合のために準備していない...

+0

うわー!それについて知らなかった、私は細胞を再利用する必要はありません。それが私の問題を解決しました! ありがとうございます! – Ibai