This uiimageview use sdwebimage load on the network picture.
Tableview now want to dynamically set the height of each row corresponding to load the picture height.
However, to obtain cell where uiimageview object error.
- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath
{
UIImageView * img = (UIImageView *) [[tableView cellForRowAtIndexPath: indexPath]. Subviews objectAtIndex: 0];
return img.frame.size.height;
}
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
static NSString * CellIdentifier = @ "Cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: CellIdentifier] autorelease];
}
/ / Image url address
NSString * str = [[[dataArr objectAtIndex: indexPath.row] objectForKey: @ "file"] objectForKey: @ "key"];
UIImageView * img1 = [[UIImageView alloc] initWithFrame: CGRectMake (100, 0, 192, 100)];
[Img1 setImageWithURL: [NSURL URLWithString: [NSString stringWithFormat: ImgUrl, str]]];
[Cell addSubview: img1];
[Img1 release];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.layer.borderColor = [UIColor blackColor]. CGColor;
cell.layer.borderWidth = 2;
return cell;
}
Reply:
If you want to dynamically generate a high degree, you'll have to get the content when it has been calculated for each CELL height; generated content you can draw on cell's contentView, and then calculate the height of contentView and then into an array, so that in this way there - (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath, you can go to get through each one indexPath cell height.
As to why you would go wrong, is that you can not clear UITableView each method call sequence, tableView: cellForRowAtIndexPath in tableView: heightForRowAtIndexPath later, you have not been born, how could speak first? So wrong.
You go to Apple's UITableView documentation more research, google about someone else's interpretation is required.
SO. . Gone.
Reply:
This approach, I considered, that is generated for each CELL, it will correspond to the height of the saved.
Then heightForRowAtIndexPath method indexPath obtain the corresponding height.
Some questions, since after cellForRowAtIndexPath is heightForRowAtIndexPath, then heightForRowAtIndexPath methods in use arrays should be empty.
I first found via NSLog output cellForRowAtIndexPath content, followed by the contents of the output heightForRowAtIndexPath.
Reply:
sorry, just tried it.
indeed in cellForRowAtIndexPath after heightForRowAtIndexPath.
The problem now is that by SDWebImage the setImageWithURL way to set imageview image, gets less than image height.
That is image1.image.size.height; acquired is 0.00000
Reply:
No, you check again, heightForRowAtIndexPath will first print.
Reply:
Right, above a typo.
Indeed heightForRowAtIndexPath in front.
The problem now is that by SDWebImage the setImageWithURL way to set imageview image, gets less than image height.
Just looked at the source code, this method is asynchronous download setImageWithURL obtain high image, image object also to nil, do not know what an elegant way to solve.
I sent you a private letter, easy to add a Q do?
Reply:
Pictures loaded after:
[Tableview beginUpdates];
[Tableview endUpdates];
This time, tableview height of cell cycle again, this time you should be able to return to the correct height.
Reply:
Can you elaborate? Not really understand.
Reply:
This method should in principle heightForRowAtIndexPath calculate the height from the data source, and has nothing to do with cell
Reply:
En 8th floor method can try!
Reply:
There are two ways you reference.
1 SD in the library after downloading each image will be a callback, you count in the callback, when the count and the count of your list of resources consistent with the time, reloadData, reloadData this method to re-execute heightForRowAtIndexPath.
2 Use the synchronization method to download resources, downloaded, read in the local equivalent of the picture. At that time, you can take the picture height.
Reply:
You just need to put your cell in the displayed content, in cellForRowAtIndexPath before, calculated in heightForRowAtIndexPath inside.
Similar: Data array array, in heightForRowAtIndexPath where each row of the array to count out the height. And then populate the data in cellForRowAtIndexPath go!
Reply:
Landlord, I recently also dynamically change the cell height studying this issue, I ask you how to solve
No comments:
Post a Comment