Posts

Post not yet marked as solved
1 Replies
1.5k Views
We’re attempting to use UICollectionView compositional layout to describe a section layout, but it’s giving us some trouble. What we’d like to achieve: A total of 7 cells 3 cells stacked, each 30% height and 100% width, with orthogonal scrolling to see the next 3 When the user reaches the last cell, it would be 100% height and 100% width of the container. ASCII art and screenshots of the imperfect example are below. Our starting point was Apple’s example code, specifically OrthogonalScrollingViewController, but what we’ve found is if we expand the widths there, the height settings seem to longer be respected. The most basic version of a layout that we tried is this: func createLayout() -> UICollectionViewLayout { let layout = UICollectionViewCompositionalLayout { (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in // Small items at roughly 30% of the container height. let smallItem = NSCollectionLayoutItem( layoutSize: NSCollectionLayoutSize( widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(0.3) ) ) // The large item should be 100% of the container width. let largeItem = NSCollectionLayoutItem( layoutSize: NSCollectionLayoutSize( widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0) ) ) // We want 3 items to appear stacked with orthogonal scrolling. let smallItemGroup = NSCollectionLayoutGroup.vertical( layoutSize: NSCollectionLayoutSize( widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0) ), subitem: smallItem, count: 3 ) let containerGroup = NSCollectionLayoutGroup.horizontal( layoutSize: NSCollectionLayoutSize( widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(0.5) ), subitems: [smallItemGroup, largeItem] ) let section = NSCollectionLayoutSection(group: containerGroup) section.orthogonalScrollingBehavior = .paging return section } return layout } We’ve tried many variations of nested groups and using the .vertical and .horizontal initializers, but each of them has the same result: The last cell is always the same size as all the others. // +------------------------------+ These would be off-screen // | +-------------------------+ | +-------------------------+ +-------------------------+ // | | 1 | | | 4 | | | // | +-------------------------+ | +-------------------------+ | | // | +-------------------------+ | +-------------------------+ | | // | | 2 | | | 5 | | 7 | // | +-------------------------+ | +-------------------------+ | | // | +-------------------------+ | +-------------------------+ | | // | | 3 | | | 6 | | | // | +-------------------------+ | +-------------------------+ +-------------------------+ // | | // | | // | | // | rest of the screen | // | | // | | // | | // | | // +------------------------------+ The last cell in the third screenshot, (0,6), is the one we want 100% height of the section. Is there a way to achieve this layout where the last cell is 100% of the section height?
Posted
by ackack.
Last updated
.
Post not yet marked as solved
0 Replies
454 Views
I have an array of HKQuantitySample and I'd like to convert it to JSON to POST it to a web service. Are there any tools or best practices to make this easy? I've seen a couple of different examples where the code takes pieces of data off of HKQuantitySample (or any HKSample) and sends only those pieces -- usually just the value. What if I want the entire HKQuantitySample object? Today, I have code that uses an Extension to apply Encodable and then I implement encode(to:) to capture the fields up the object hierarchy. Encodable makes that easy, but I feel like I'm inventing the wheel. I also have to cast HKSample to the subtypes to make it work -- not a problem, but definitely an extra step. Has anyone else already solved this problem? Any recommendations or suggestions?
Posted
by ackack.
Last updated
.
Post not yet marked as solved
1 Replies
9.2k Views
I have an app that's live and it's experiencing a very small number of crashes. The crashes are throwing an NSInvalidArgumentException with the message "Application tried to present modally an active controller <UIAlertController: 0x122867800>." I use a UIAlertController in a few places, but they all fit the same usage pattern below where self is a UIViewController: UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"..." message:@"..." preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:alert animated:YES completion:nil]; After spending a lot of time looking through the code, debugging, and looking for others with the same issue, I guess I have 2 questions: What I *think* this error message is trying to tell me is that I'm trying to present the same active view controller instance on itself -- that I have a pointer to a view controller, it's already displayed modally, and I'm trying to display the same view controller again. In this scenario that's not true. Is there something I'm not understanding about the error message? Is it trying to tell me something different? The exception traces don't contain much helpful information and I haven't been able to reproduce this on a device or simulator. Does anyone have advice for tracking down this sort of exception? I do have scenarios where a view controller is presented modally, and it could present a UIAlertController, so I thought there might be some sort of race condition where the alert was trying to be displayed before the view controller was ready, but I haven't been able to force that to happen in local testing, either. Any thoughts or feedback on this are appreciated! Thanks!
Posted
by ackack.
Last updated
.