私のTableViewでは、画像と2つのラベルを設定していますが、うまく塗りつぶされています。しかし、TableViewを下にスクロールしてから、塗りつぶされたセルを再表示すると、塗り替えられます。今、私は自分のImageViewにURLからの画像を入力しているので、ユーザーに負荷がかかります。
したがって、TableViewを制限して、セルが最初にいっぱいになった場合に、再びいっぱいにならないようにすることはできますか。
これは私のコードです:
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell * cell = [atableView dequeueReusableCellWithIdentifier: nil];
if(cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier];
ChannelList *channelList = nil;
if (searchedData.count ==0) {
channelList = [channelAllData objectAtIndex:[indexPath section]];
} else {
channelList = [searchedData objectAtIndex:[indexPath section]];
}
UIImageView *aImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 50, 50)];
aImageView.image = [UIImage imageNamed:@"tv-defolt.png"];
NSString * mystr = [channelList channelLogo];
if (mystr.length !=0) {
//get a dispatch queue
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSString * str = [NSString stringWithFormat:@"http://manektech.net/mttv/Channel/%@",[channelList channelLogo]];
NSData *image = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]];
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
aImageView.image = [UIImage imageWithData:image];
});
});
} else {
aImageView.image = [UIImage imageNamed:@"tv-defolt.png"];
}
[cell addSubview:aImageView];
UILabel *nameTextLabel = [[UILabel alloc] initWithFrame: CGRectMake(80, 15, 175, 20)];
nameTextLabel.textColor = [UIColor blackColor];
nameTextLabel.backgroundColor = [UIColor clearColor];
nameTextLabel.text = [channelList channelName];
nameTextLabel.font = [UIFont fontWithName:@"Arial" size:14];
[cell addSubview:nameTextLabel];
UILabel *genreTextLabel = [[UILabel alloc] initWithFrame: CGRectMake(80, 35, 175, 20)];
genreTextLabel.textColor = [UIColor grayColor];
genreTextLabel.backgroundColor = [UIColor clearColor];
NSString * str = [NSString stringWithFormat:@"%@ | %@",[channelList channelType],[channelList channelCounry]];
genreTextLabel.text = str;
genreTextLabel.font = [UIFont fontWithName:@"Arial" size:14];
[cell addSubview:genreTextLabel];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
return cell;
}