forkingdog / uitableview-fdtemplatelayoutcell Goto Github PK
View Code? Open in Web Editor NEWTemplate auto layout cell for automatically UITableViewCell height calculating
License: MIT License
Template auto layout cell for automatically UITableViewCell height calculating
License: MIT License
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x130222c00 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x174445e50> (
<NSKeyValueObservance 0x1742d19c0: Observer: 0x12f561dc0, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x17424bfd0>
<NSKeyValueObservance 0x1742d1b80: Observer: 0x12f561dc0, Key path: contentSize, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x17424c150>
<NSKeyValueObservance 0x1742d1bf0: Observer: 0x12f561dc0, Key path: frame, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x17424c2a0>
<NSKeyValueObservance 0x1742d1640: Observer: 0x12f561dc0, Key path: contentInset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x17424c240>
)'
When you use SDWebImage to download pictures, the height of the image in cell is elongated。Images are not adaptive cell good height。Hope to improve it
elegant solution for dynamic height problem of uitableview!
i make some combination to RETableViewManager also a great library for uitableview.
here it is.
https://github.com/boska/RETableViewManager-FDTemplateLayoutCell
(void)fd_reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
NSMutableArray *rows = self.fd_cellHeightCache.sections[idx];
运行到这句话崩溃,调用如下:
[_displayTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
朋友圈里面的图片从一张到九张,在布局上面改如何设置,你的库会解决这个问题吗?
大约每页有20个项目,图片异步加载,行高已经正确设置,没有问题,只是加载出下一页时,会有短暂卡顿,应该是在算高度,而使用sizeFit 又无法在线程中,该怎么解决呢?
同一个Cell会用到某两个Label需要动态高度,经过测试一般都是第二个Label高度会不对,是我约束设置的不对吗?如果是上述情况,需要动态高度的Label需要怎么设置高度呢?
目前解决方法只能:
[cell updateConstraintsIfNeeded];
[cell layoutIfNeeded];
如题
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (0), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
*** First throw call stack:
(
0 CoreFoundation 0x008a5746 exceptionPreprocess + 182
1 libobjc.A.dylib 0x0052ea97 objc_exception_throw + 44
2 CoreFoundation 0x008a55da +[NSException raise:format:arguments:] + 138
3 Foundation 0x0019b720 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
4 UIKit 0x00f79cfc -[UITableView _endCellAnimationsWithContext:] + 13530
5 UIKit 0x00f90d81 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 337
6 UIKit 0x00f90dc1 -[UITableView insertRowsAtIndexPaths:withRowAnimation:] + 56
7 Demo 0x0003c678 -[UITableView(FDTemplateLayoutCellAutomaticallyCacheInvalidation) fd_insertRowsAtIndexPaths:withRowAnimation:] + 344
8 Demo 0x00040bb0 -[FDFeedViewController insertRow] + 704
9 Demo 0x000407a5 -[FDFeedViewController actionSheet:clickedButtonAtIndex:] + 181
10 UIKit 0x01463031 -[UIActionSheet _prepareToDismissForTappedIndex:] + 192
11 UIKit 0x01462f09 __37-[UIActionSheet _prepareAlertActions]_block_invoke114 + 56
12 UIKit 0x0114233f -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 72
13 UIKit 0x011422f2 -[UIAlertController _dismissAnimated:triggeringAction:] + 56
14 UIKit 0x01141ede -[UIAlertController _actionViewTapped:] + 68
15 libobjc.A.dylib 0x00544771 -[NSObject performSelector:withObject:] + 70
16 UIKit 0x01313465 -[_UIAlertControllerActionView _triggerSelect] + 60
17 UIKit 0x013130ac -[_UIAlertControllerActionView touchesEnded:withEvent:] + 187
18 UIKit 0x00ed0cfa -[UIWindow _sendTouchesForEvent:] + 874
19 UIKit 0x00ed17d6 -[UIWindow sendEvent:] + 792
20 UIKit 0x00e8f6d1 -[UIApplication sendEvent:] + 242
21 UIKit 0x00e9fb08 _UIApplicationHandleEventFromQueueEvent + 21484
22 UIKit 0x00e73337 _UIApplicationHandleEventQueue + 2300
23 CoreFoundation 0x007c706f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
24 CoreFoundation 0x007bcb7d __CFRunLoopDoSources0 + 253
25 CoreFoundation 0x007bc0d8 __CFRunLoopRun + 952
26 CoreFoundation 0x007bba5b CFRunLoopRunSpecific + 443
27 CoreFoundation 0x007bb88b CFRunLoopRunInMode + 123
28 GraphicsServices 0x049602c9 GSEventRunModal + 192
29 GraphicsServices 0x04960106 GSEventRun + 104
30 UIKit 0x00e77106 UIApplicationMain + 1526
31 Demo 0x00041cea main + 138
32 libdyld.dylib 0x02e44ac9 start + 1
33 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
There is a memory leak problem with cell.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
//swizzle代码
});
// Add a hard width constraint to make dynamic content views (like labels) expand vertically instead
// of growing horizontally, in a flow-layout manner.
It is good idea, but if i use preferredMaxLayoutWidth for uilabel,width constraint is not essential,is that right?
ps: before using systemLayoutSizeFittingSize, setNeedsLayout() and layoutIfNeeded() is not need call?
The uncached version works without any problems.I tried to use the cached version:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [tableView fd_heightForCellWithIdentifier:@"identifer" cacheByIndexPath:indexPath configuration:^(id cell) {
// configurations
}];
}
I used it on the collapse table view example Apple provided here:
https://developer.apple.com/library/ios/samplecode/TableViewUpdates/Introduction/Intro.html
When I tap on a table header cell open works great with the correct height calculated using auto layout. When I tap again on the same header cell to close the section the following error occurs:
2015-06-18 16:20:59.911 HotelRoomServiceDemo[10042:607] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x00b111e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0088c8e5 objc_exception_throw + 44
2 CoreFoundation 0x00ab25ba -[__NSArrayM removeObjectAtIndex:] + 442
3 HotelRoomServiceDemo 0x000ea3c9 __110-[UITableView(FDTemplateLayoutCellAutomaticallyCacheInvalidation) fd_deleteRowsAtIndexPaths:withRowAnimation:]_block_invoke + 297
4 CoreFoundation 0x00b8d99d __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 61
5 CoreFoundation 0x00b8d8d2 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 258
6 CoreFoundation 0x00b0aca5 -[NSArray enumerateObjectsUsingBlock:] + 53
7 HotelRoomServiceDemo 0x000ea23a -[UITableView(FDTemplateLayoutCellAutomaticallyCacheInvalidation) fd_deleteRowsAtIndexPaths:withRowAnimation:] + 282
8 UIKit 0x0c351da6 -[UITableViewAccessibility(Accessibility) deleteRowsAtIndexPaths:withRowAnimation:] + 65
9 HotelRoomServiceDemo 0x00099ed9 _TFC20HotelRoomServiceDemo29MMCollapseTableViewController17sectionHeaderViewfS0_FTCS_26MMCollapseTableSectionView13sectionClosedSi_T_ + 1273
10 HotelRoomServiceDemo 0x0009a730 _TTWC20HotelRoomServiceDemo29MMCollapseTableViewControllerS_34MMCollapseTableSectionViewDelegateS_FS1_17sectionHeaderViewUS1___fQPS1_FTCS_26MMCollapseTableSectionView13sectionClosedSi_T_ + 32
11 HotelRoomServiceDemo 0x00090185 _TFC20HotelRoomServiceDemo26MMCollapseTableSectionView24toggleOpenWithUserActionfS0_FSbT_ + 1589
12 HotelRoomServiceDemo 0x00090249 _TFC20HotelRoomServiceDemo26MMCollapseTableSectionView10toggleOpenfS0_FT_T_ + 57
13 HotelRoomServiceDemo 0x00090282 _TToFC20HotelRoomServiceDemo26MMCollapseTableSectionView10toggleOpenfS0_FT_T_ + 34
14 UIKit 0x013214f4 _UIGestureRecognizerSendActions + 230
15 UIKit 0x01320168 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
16 UIKit 0x01321bdd -[UIGestureRecognizer _delayedUpdateGesture] + 60
17 UIKit 0x0132513d ___UIGestureRecognizerUpdate_block_invoke + 57
18 UIKit 0x013250be _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
19 UIKit 0x0131b7ac _UIGestureRecognizerUpdate + 199
20 UIKit 0x00fc6a5a -[UIWindow _sendGesturesForEvent:] + 1291
21 UIKit 0x00fc7971 -[UIWindow sendEvent:] + 1021
22 UIKit 0x00f995f2 -[UIApplication sendEvent:] + 242
23 UIKit 0x00f83353 _UIApplicationHandleEventQueue + 11455
24 CoreFoundation 0x00a9a77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x00a9a10b __CFRunLoopDoSources0 + 235
26 CoreFoundation 0x00ab71ae __CFRunLoopRun + 910
27 CoreFoundation 0x00ab69d3 CFRunLoopRunSpecific + 467
28 CoreFoundation 0x00ab67eb CFRunLoopRunInMode + 123
29 GraphicsServices 0x038ac5ee GSEventRunModal + 192
30 GraphicsServices 0x038ac42b GSEventRun + 104
31 UIKit 0x00f85f9b UIApplicationMain + 1225
32 HotelRoomServiceDemo 0x000ada94 main + 180
33 libdyld.dylib 0x034c76d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
请问- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath这个方法是不是会调用两次呢?
I remember the auto layout engine will calculate the frame based on the constraints, why you explicitly call systemLayoutSizeFittingSize?
I tried to delete the delegate and it turned out the imageView's constraint is still the same, but the height is half of the height constraint, and the image itself size is not fully occupied, so I am thinking, will this be a bug for your imageView not correctly set?
For exmaple, in the phil cell with the beauty's image, size is 160,97, while constraint is 160,195 and alignment rect is 160,195 as well.
If set the delegate, the size is 160,195, constraint 160,195, alignment rect 160,195.
挺实用的,持续关注中,等有空了我也加入pull request
I used it on the collapse table view example Apple provided here:
https://developer.apple.com/library/ios/samplecode/TableViewUpdates/Introduction/Intro.html
I used the not cached version of this plugin. When I click on a section header to open the rows in the section then I get the following error:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<_UIScrollViewAutomaticContentSizeConstraint:0x7a09e6a0 UITableView:0x7c1d4400.contentHeight{id: 178} == -5.000000>"
)
Will attempt to recover by breaking constraint
<_UIScrollViewAutomaticContentSizeConstraint:0x7a09e6a0 UITableView:0x7c1d4400.contentHeight{id: 178} == -5.000000>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
My Custom Cell looks like this:
class MyCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupView()
}
private func setupView() {
let addButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
self.contentView.addSubview(addButton)
addButton.snp_makeConstraints { (make) -> Void in
make.edges.equalTo(self.contentView).priorityLow()
}
}
}
How can I fix this issue?
tableView.fd_heightForCellWithIdentifier("cellId", configuration: { (cell:UITableviewCell) -> Void in
self.configureCell(cell, atIndexPath: indexPath)
})
does not work
In my app I usually have tables with ~150 rows.
Rows are very simple:
When table view creates I have delay for about 3 seconds before it appears (iPhone 5 iOS 8.3)...
I tried to use new - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration;
But seems like it starts caching heights only when I scroll through them for second time.
Also I noticed that - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
is called 3 times on init stage and all these 3 times heights are calculated from scratch... Here's my implementation:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"step 1: %@", indexPath);
return [tableView fd_heightForCellWithIdentifier:@"DetailViewTableViewCell" cacheByIndexPath:indexPath configuration:^(iptvDetailedEPGTableViewCell *cell) {
// Configure this cell with data, same as what you've done in "-tableView:cellForRowAtIndexPath:"
NSLog(@"step 2: %@", indexPath); // Should not be called if using cached height, right?
[self configureCell:cell forIndexPath:indexPath];
}];
}
I get both log messages (3 * table length) times at init and than 1 more time when scrolling through the tableView. Only when scrolling second time I see only 1 log message.
Is it normal behaviour?
Thanks.
我想问下,就是类似微信朋友圈的那种布局,九张图片如果使用autolayout怎么添加约束,我现在是用一个View来做这几张图片的背景,但是用添加约束之后,使用autolayout,高度并没有发生改变。
Why the 'didSelectRowAtIndexPath' method cann't be called in your demo project ?
⇒ pod install
Analyzing dependencies
[!] Unable to find a specification for UITableView+FDTemplateLayoutCell
使用Xib布局 registerNib:forCellReuseIdentifier:注册了Cell
计算高度时
BOOL autoLayoutEnabled = cell.contentView.constraints.count > 0 && !cell.fd_enforceFrameLayout;
这句中的cell.contentView.constraints 是个空数组 但是我用了AutoLayout了
- (void)fd_deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
{
if (self.fd_autoCacheInvalidationEnabled) {
[self.fd_cellHeightCache buildHeightCachesAtIndexPathsIfNeeded:indexPaths];
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
NSMutableArray *rows = self.fd_cellHeightCache.sections[indexPath.section];
[rows removeObjectAtIndex:indexPath.row];
}];
}
[self fd_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation]; // Primary call
}
I has tested it on iOS 6, It can not calculate the rowHeight correctly, but I have read your blog. You said it can surpot ios6,I have delete "self.tableView.estimatedRowHeight = 200;”
如题,解决方案:
//@note:这种解决方案在iOS 7.0+能很好的解决问题,但是如若解决iOS 6.0的话,则无效了。
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [tableView fd_heightForCellWithIdentifier:@"xxxxCellIdentifier"
cacheByIndexPath:indexPath
configuration:^(xxxCell *cell) {
[self configureCell:cell atIndexPath:indexPath];
}];
}
//解决办法就是在获取高度之后判断一下,是否为空,如果为空的话,那就用cell的高度设置一下就可以了。
CGSize fittingSize = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
if (fittingSize.height == 0) {
fittingSize.height = cell.frame.size.height;
}
我的cell是代码写的可以吗?不用nib的画,fd_templateCellForReuseIdentifier这个方法就会断言必需注册identifier,并退出程序。
I am using xibs in my project. I followed your guidelines. But, still I am not able to make it work with xib.
Please provide the details, for how to add it with xib.
cell 从上到下有一个label,一个scroll view, 另外一个label。scroll view在没有内容的时候,会隐藏起来。这种情况下,似乎高度还是会算上scroll view,导致中间空白。有解决办法吗?
如果需要分层的话,用到Section的情况比较多,所以建议把这个加上。
If you run app on iOS7 simulator, you will get this one:
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fa87179cf90 H:|-(16)-[UILabel:0x7fa87179b200] (Names: '|':UITableViewCellContentView:0x7fa87179b120 )>",
"<NSLayoutConstraint:0x7fa87179d080 H:[UIImageView:0x7fa87179cb80]-(>=16)-| (Names: '|':UITableViewCellContentView:0x7fa87179b120 )>",
"<NSLayoutConstraint:0x7fa87179d120 UIImageView:0x7fa87179cb80.leading == UILabel:0x7fa87179b200.leading>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa87179e530 h=--& v=--& H:[UITableViewCellContentView:0x7fa87179b120(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fa87179d120 UIImageView:0x7fa87179cb80.leading == UILabel:0x7fa87179b200.leading>```
Hi,
感谢作者的辛勤劳动,这两天在用感觉比较方便,但遇到些问题
cell中的imageView加上TapGesture之后会crash,
是否对tableView.headerView是不是默认也进行了自动布局?
http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/
I am trying to make the view like shown in above link where imageview and contentview of the feed are not of fix size... i have tried your library but dont know if i m missing something..... i m not using autolayout for my app... but using autolayout only for the tableview cell in the xib...is that whats causing the problem??? please help
..
contentLabel在代码中并没有看到显示的计算,
请问它的计算高度的地方在哪里?还望赐教,多谢。
I have one image view inside cell content that loads photo from server.
image view content mode is aspect fill and only width has been defined using autolayout in storyboard.
height should be increased dynamically based on loaded photo size.
constraints for cell content view has been already self-satisfied.
what am I missing?
如题
Delete all setions;
insert a row;
Tableview的锅,但是demo crash玩着玩着crash总归不太好吧。
Amazing library, I'm using it a lot! ... but I found a problem :P
Looks like rotations and caching are not good friends right now.
I have two ideas
How to use with image from internet download asynchronies when set content of cell. Size of the image may already known
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.