2011-01-12 4 views
1

HIでoverlapingさiPhone:カスタムセルは</p> <p>を、これは私のコードされてスクロールしたとき</p> <p>私のテーブルビュー最初のカスタムセルが乗って他のセル上で、私はテーブルビューに取り組んでいますお互い

#import UIKit/UIKit.h 

@interface MyTweetViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> { 

IBOutlet UITableView *tweetsTableView; 

NSMutableArray *tweetArray; 

} 

@property (nonatomic, retain) IBOutlet UITableView *tweetsTableView; 

@end 

#import "MyTweetViewController.h" 

@implementation MyTweetViewController 

@synthesize tweetsTableView; 

- (void)viewDidLoad { 

     tweetArray = [[NSMutableArray alloc] init]; 

    [tweetsTableView setBackgroundColor:[UIColor clearColor]]; 

    [super viewDidLoad]; 
} 

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    // Return the number of sections. 

    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

// Return the number of rows in the section. 

    return [tweetArray count]; 

} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 

return 80; 

} 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

{ 

    [cell setBackgroundColor:[UIColor clearColor]]; 

} 


//Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *identifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 


if(!cell) { 


     cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:identifier]; 

     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    } 

cell.accessoryType = UITableViewCellAccessoryNone; 

UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(72,3,242,15)]; 

name.text = (NSString*)[(Tweet*)[tweetArray objectAtIndex:indexPath.row] userName]; 

[name setFont:[UIFont fontWithName:@"Helvetica" size:14]]; 

    name.textColor=[UIColor colorWithRed:250 green:250 blue:210 alpha:0.5]; 

    [name setBackgroundColor:[UIColor clearColor]]; 

    UILabel * tweetLabel = [[UILabel alloc]initWithFrame:CGRectMake(72,20,242,60)]; 

    tweetLabel.text = (NSString*)[(Tweet*)[tweetArray objectAtIndex:indexPath.row] tweet]; 

tweetLabel.numberOfLines = 3; 

    tweetLabel.textColor=[UIColor colorWithRed:252 green:148 blue:31 alpha:1]; 

    [tweetLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]]; 

    [tweetLabel setBackgroundColor:[UIColor clearColor]]; 

    NSLog(@" lblUserTweet : %@ ",name.text); 

    UIImageView *myImage = [[UIImageView alloc]initWithFrame:CGRectMake(6,3,58,49)]; 

NSURL *url = [NSURL URLWithString:[(Tweet*)[tweetArray objectAtIndex:indexPath.row] image_url]]; 

NSData *data = [NSData dataWithContentsOfURL:url]; 

    [myImage setImage: [UIImage imageWithData:data]]; 

[cell.contentView addSubview:myImage]; 

    [cell.contentView addSubview:tweetLabel]; 

    [cell.contentView addSubview:name]; 


    return cell; 

} 

- (void)dealloc { 

    [tweetsTableView release]; 

    [tweetArray release]; 

     [super dealloc]; 
} 
+0

HI tweetsTableViewは非常に遅いロードされると、テーブルビューが非常に遅いスクロールしたときに、あなたが私を提案することができます –

答えて

3

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil]; 

すべてのベストをセルを再使用しないでください。

+0

こんにちはWarrior、私のためのこの作品、ありがとう –

+1

はい、なぜ、キャッシュ機能を無視すると簡単なバグを修正するのは簡単ですか?セットアップコードは、いくつかのオブジェクト、BTWをリークします。 – Eiko

+0

こんにちはWarrior、このテーブルビューは、非常に遅いロードすることができますあなたは私を案内することができます –

0

細胞の高さは適切ではないと思います。

コードを確認してください。

+0

はロビン –

+0

こんにちはtweetsTableViewが非常に遅いロードされると、テーブルビュー、非常にゆっくりスクロールしているスクロールするとき、あなたは私を提案することができますありがとう –

1

潜在的に再使用されるセルにコンポーネントを繰り返し追加します。

if (!cell) { }ブロックにラベルの追加などの作成を移動し、後でこれらのコンポーネントのみを構成する必要があります。

正しいUI要素を見つける1つの方法は、そのブロックに割り当てたtagで検索し、別のよりエレガントな方法は、カスタムのUITableViewCellサブクラスをこれらの要素のプロパティと共に使用することです。

編集:それらのビューを追加した後でリリースします。そうしないと、リークするだけです。

+0

ありがとうえいこ、私はまた、私はあなたが私を提案することができます –

0

NSString * identifier = @ [NSString stringWithFormat:@ "%d"、indexPath.row]をセル識別子として使用できます。細胞を他の細胞と区別します。

関連する問題

 関連する問題