Thursday, September 26, 2013

Why am I in a cell in tableview content always appears in another cell

My cell probably show similar as in Sina microblogging cell contents

In general is such a design:

1, a first landing of the text to be displayed asynchronously downloaded stored in the cache, cell displayed when text information is taken from the cache

2, and then displayed whenever a cell when the cell on the asynchronous download and display
Avatar
3, whenever it shows a cell, if the cell has posted image user, then open up a separate thread asynchronously download and display images

But the three, the downloaded images always somehow appeared in other cell in

May I ask how is this going?

Thank you
Reply:
UITableViewCell is reusable, of course you can not reuse it, reuse, when you load the picture in front of a View or load text View also above, you need to first remove the child view;
If the cell is to define your own subclass of all cell contents are generated internally in this class, then put these views Frame height is set to 0, and then re-load the next set the height can be
Reply:
quote 1 floor vikiliu0310 reply:
UITableViewCell is reusable, of course you can not reuse it, reuse it in front of you, or loading pictures View View also loaded text above, you need to first remove the child view;
If the cell is to define your own subclass of all cell contents are generated internally in this class, then put these views Frame height is set to 0, and then re-load the next set the height on it


A little look Sidongfeidong

Use code indicates that about it?
Reply:
cited two floor iOSLearn reply:
quote 1 floor vikiliu0310 reply: UITableViewCell is reusable, of course you can not reuse it, reuse it, View the picture in front of you to load or load text View also above, you need to first remove the child view;
If the cell is to define your own subclass of all cell contents are generated internally in this class, then put these views Frame height is set to 0, and then re-load the next set the height on it

Like to understand a little bit to see non ......

Probably thinking I said, I want to see what you write is how I can know cause of your problem
Reply:
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
NSInteger nowRow = indexPath.row;
HomeCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "HomeCell" forIndexPath: indexPath]; / / cell subclasses
/ / Associated with cell interior view
[Cell linkWithTag];
/ / Read cache data
NSString * userFaceString = [[appDelegate.homeConArr objectAtIndex: nowRow] objectForKey: @ "face"]; / / avatar
NSString * userName = [[appDelegate.homeConArr objectAtIndex: nowRow] objectForKey: @ "uname"]; / / username
NSString * userCon = [[appDelegate.homeConArr objectAtIndex: nowRow] objectForKey: @ "content"]; / / micro-blog content
NSInteger hasImg = [[[appDelegate.homeConArr objectAtIndex: nowRow] objectForKey: @ "type"] intValue]; / / if there microblogging picture



/ / Write the contents Name / article
cell.userName.text = userName;
cell.userCon.text = userCon;
/ / Create the refresh avatar thread and join the queue starts
NSArray * faceURLArray = [faceDic allKeys];
BOOL hasFaceCache = [faceURLArray containsObject: userFaceString];
if (! hasFaceCache) {/ / If there is no cache
[Cell.userFace setImage: [UIImage imageNamed: @ "Placeholder.png"]]; / / stations avatar
NSArray * dicKeyArr = [[NSArray alloc] initWithObjects: userFaceString, indexPath, nil];
NSInvocationOperation * faceLoadOperation = [[NSInvocationOperation alloc] initWithTarget: self selector: @ selector (loadFace :) object: dicKeyArr];
[ThreadQueue addOperation: faceLoadOperation];
} Else {
[Cell.userFace setImage: [faceDic objectForKey: userFaceString]];
}
/ / Thread image
Download articleif (hasImg) {
/ / Small map address
NSString * smaImgUrlStr = [[[appDelegate.homeConArr objectAtIndex: nowRow] objectForKey: @ "type_data"] objectForKey: @ "thumburl"];
NSURL * imgUrl = [NSURL URLWithString: smaImgUrlStr];
cell.conImage.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: imgUrl]];
NSLog (@ "% @", smaImgUrlStr);
} Else {
/ /
}
}

Basically this

Reuse cell images appear only articles became confused

Others such as Avatar, text and no mess, do not know how it is?
Reply:
You reuse mechanism that does not use
Reply:
5th Floor yuhuangc reply quote:
you reuse mechanism that does not use


HomeCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "HomeCell" forIndexPath: indexPath];

This is re-ah
Reply:
Thank vikiliu0310

I read your explanation, I do not know what I understand, right?

After using cell reuse, after a cell within the control's content is set before a cell contents, if you want to change, you must re-set the new value?

However, I have to set up a cell within the control tag after, this control has appeared in the other cell, do not know what is the situation?
Reply:
Where Does Your HomeCell initialized, and your sentence HomeCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "HomeCell" forIndexPath: indexPath]; does not reuse, simply remove the memory cell, the back does not use multiplexing
Reply:
8th Floor yuhuangc reply quote:
Where Does Your HomeCell initialized, and your sentence HomeCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "HomeCell "forIndexPath: indexPath]; does not reuse, just remove the memory cell, the back does not use multiplexing


My UITableViewCell is defined in the storyboard Identifier as HomeCell the cell, it is not possible to say UITableViewCell initialized in the storyboard,

In addition, I also made a separate call HomeCell the UITableViewCell subclass used to correlate the HomeCell storyboard
Reply:
Well, to understand, I basically use the code to achieve, and did not use IB, storyboard.

General wording of the code reuse is
static NSString * CellIdentifier = @ "cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath: indexPath];
/ / Configure the cell ...
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat: @ "% d", indexPath.row];
return cell;

You can put into your custom UITableViewCell class HomeCell try
Reply:
10th floor yuhuangc reply quote:
Well, understand, I basically use the code, and did not use IB, storyboard.

General wording of the code reuse is
static NSString * CellIdentifier = @ "cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier ......


Yes, the two methods can be,

But why to a cell within the control sets the tag after the controls again arose within another cell?
Reply:
> But why to a cell within the control sets the tag after the controls again arose within another cell?
Because reuse ah. Surely you did not set the content of a cell, you said the other cell is certainly later scroll to the visible range.

Reply:
12th floor ynb119 reply quote:
> But why to a cell within the control sets the tag after the controls again appeared in other cell the?
Because reuse ah. Surely you did not set the content of a cell, you said the other cell is certainly later scroll to the visible range.


I had a rub, it will lead to set up a tag reuse ah? !

Do I have to give the other cell is also defined a useless this control?
Reply:
Reuse is exactly the same thing (with the same piece of memory), of course, including setting tag.
Reuse is then the inevitable, the properties are set again on it. Do not set the attribute appears you this example to nil else inside to be able to

No comments:

Post a Comment