Closed mrhaxic closed 7 years ago
Hi @mrhaxic, I can't reproduce the crash. Tested in Xcode 8.1 simulator iPhone SE. Are you talking about the example project included with this repository?
Please mention step by step process to reproduce the crash.
Hi @rishi420 , Not the example project . lets me show you the example of the code I used it without storyboard (FYI)
.h file
#import <UIKit/UIKit.h>
#import "MJGLayoutKit.h"
#import "ExpandableTableView.h"
@interface ExampleController : UIViewController <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UIView *layoutContainer;
@property (nonatomic, strong) MJGLKRootView *mainLayout;
@property (strong,nonatomic) ExpandableTableView *tableView;
@end
.m file
#import "ExampleController.h"
#import <Foundation/Foundation.h>
@interface ExampleController ()
@property (nonatomic, strong) NSArray *cells;
@property (nonatomic, strong) NSArray *headers;
@end
@implementation ExampleController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [ExpandableTableView new];
self.tableView.x = 0;
self.tableView.y = 0;
self.tableView.width = self.view.frame.size.width;
self.tableView.height = self.view.frame.size.height;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.cells = @[@"Cell 1", @"Cell 2", @"Cell 3", @"Cell 4", @"Cell 5", @"Cell 6", @"Cell 7", @"Cell 8"];
self.headers = @[@"Header 1", @"Header 2", @"Header 3", @"Header 4", @"Header 5", @"Header 6", @"Header 7", @"Header 8", @"Header 9", @"Header 10", @"Header 11", @"Header 12", @"Header 13", @"Header 14"];
self.tableView.allHeadersInitiallyCollapsed = YES;
self.tableView.initiallyExpandedSection = 0;
self.tableView.singleSelectionEnable = YES;
MJGLKUIViewWrapper * mjVW0 = [[MJGLKUIViewWrapper alloc] initWithUIView:self.tableView];
mjVW0.layoutSpec = MJGLKLayoutSpecMake(MJGLKSizeFillParent, MJGLKSizeWrapContent, 0.0f, UIEdgeInsetsMake(0.0f, 0.0, 0.0f, 0.0f), UIEdgeInsetsZero, MJGLKGravityCenter, MJGLKGravityCenter);
MJGLKLinearLayout *vLinearLayout = [[MJGLKLinearLayout alloc] initWithOrientation:MJGLKLinearLayoutOrientationVertical views:[NSArray arrayWithObjects:mjVW0,nil]];
vLinearLayout.layoutSpec = MJGLKLayoutSpecMake(MJGLKSizeFillParent, MJGLKSizeWrapContent, 0.0f, UIEdgeInsetsZero, UIEdgeInsetsZero, MJGLKGravityCenter, MJGLKGravityCenter);
MJGLKScrollLayout *scrollLayout = [[MJGLKScrollLayout alloc] initWithView:vLinearLayout];
scrollLayout.layoutSpec = MJGLKLayoutSpecMake(MJGLKSizeFillParent, MJGLKSizeWrapContent, 1.0f, UIEdgeInsetsZero, UIEdgeInsetsZero, MJGLKGravityCenter, MJGLKGravityCenter);
self.mainLayout = [[MJGLKRootView alloc] initWithView:vLinearLayout];
self.mainLayout.backgroundColor = [UIColor colorFromHexString:@"efeff4"];
self.mainLayout.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mainLayout.frame = self.view.bounds;
self.mainLayout.tag = 500;
[self.view addSubview:self.mainLayout];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tableView totalNumberOfRows:self.cells.count inSection:section];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *celliden = @"SalaryCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celliden];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:celliden];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = self.cells[indexPath.row];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.headers.count;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return HEADER_VIEW_HEIGHT;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [self.tableView headerWithTitle:self.headers[section] totalRows:self.cells.count inSection:section];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"section-%ld, row-%ld", (long)indexPath.section, (long)indexPath.row);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Hope this help you to reproduce the crash more
@rishi420 For your kind information I used XIB and it works, but why is not working programitacilly ? could you help me on this ?
@mrhaxic thanks for your code. It helped me regenerate the issue. It should be fixed now. Please download latest code and check again. And let me know. If the issue is not solved feel free to reopen the issue.
@rishi420 very well, to be a completed source what do you think about making differenece arrays for each header ? please find below clarification
suppose there is 4 headers (header 1,header 2, header 3, header 4) and each one have its own array like
header 1 array = @[1,2,3] thus the header will display 3 cells header 2 array = @[1,2] thus the header will display 2 cells header 3 array = @[1,2,3,4,5] thus the header will display 5 cells header 4 array = @[] thus the header will display zero cells
What do you think?
@rishi420 Well done. Sorry for bothering dear
Hi dear thanks for this class I used it but during press any header it displayed
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 8 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Any hint ?