I am trying to code a tableview with words on the left and buttons on the right for each row. Is that possible to do?
I have got the words coded for each row however I am struggling with putting the buttons on the right side and spaced evenly as well as following the screen when scrolling up and down the tableview.
At the moment I have just been adjusting the button's y axis numbers from the right side controls in the x code to make sure the buttons are evenly spaced but it is not following the scroll. Is there is an easier or more efficient way of doing this? Any help would be great.
Thanks!
You should create your own UITableViewCell. Apple has a tutorial in their documentation how to do that. It's written for Objective-c, but you can easily change it to swift. Also there are tutorials like this tutorial on YouTube.
Basically, what you need to do is creating a UITableViewCell and use it instead of the normal UITableViewCell in the cellForRowAtIndexPath. After that, you can add whatever elements you'd like to have.
Related
I'm trying to implement the following:
At the top is a segment control that, based on the user's selection (either tapping or scrolling), moves to the relevant CollectionView section.
I've been playing around for a couple of days with CollectionViews and maybe I've just confused myself with LayoutFlows and CompositionalLayouts or is that over complicating it?
I have a diffable datasource that is made up of [Sections, CellItems] but I'm struggling with how to structure it.
What is the recommended programmatic (rather than using interface builder) to do the above? I was just going to originally do 5 horizontal cells, each with a tableView but based on some other comments I've seen from Apple on the Apple forums and the move away from TableView to CollectionView at this year's WWDC, I thought I should be trying to do this properly.
Any direction would be appreciated. All my research seems to point to using orthogonalScrollingBehavior but that layouts out the sections vertically with each section scrolling horizontally.
So my question is should I be trying to do what I'm doing using a CompositionalLayout?
Well first off your segmented control idea makes this sound like you could just use a page control for the horizontal aspect and remove a lot of the collection view complexity. Something to consider anyway.
As for the data source, I think all you need is an array of arrays. Eg. [[CellItems]]. So CellItems[0] would be the first column. Then CellItems[0][0] would be the first cell. CellItems[1][2]... 2nd column 3rd cell. I do apologize as your current solution may be related to diffable datasources and I haven't had time yet to dig into those.
Start with the horizontal axis first and ignore the vertical axis. Get that working as needed. Once you have that up and running... implement another collection view into the first one's cells.
Sorry if I misunderstood the question if it was more about HOW to implement a collection view.
I am using Swift 3. I am currently using a UITableView to display a list of items - specifically a list of athlete results from a race and it has about 10 columns (e.g swim time, bike time, run time, place). I am currently using a UITableView and it works OK, but I am finding it difficult/not possible to do what I want. I found a few other solutions out here that are similar but they are using HTML/Web front ends vs swift 3 / native iOS.
I would like fixed width columns, and column headers. I want to be able to scroll left and right and up and down. I want the far left column to be fixed. This is the column with the athlete name. I want all the other columns to scroll left and right while this remains fixed.
I use an app called PowerSchool for my kids' school that illustrates the concept perfectly. Attached are two screen shots with names and grades brushed out.
Scroll View One
Scroll View Two
I am thinking that UITableView will not do this and I need to use UICollectionView or something else.
Any info to help me get started on this would be greatly appreciated. I plan to make this work on iPad and iPhone in both portrait and landscape.
Hi for this you need to two components.
Either a UIScrollView with a UITableView
or UITableViewCell inside a UICollectionView
or a UICollectionView inside a UICollectionView
This can be achieved by mixing two components or you can use some sort of library:
https://github.com/fullc0de/HKKScrollableGridView
https://github.com/kanaishinichi/TAXHeaderSheet
First of all, apologies if this question isn't meant here. I searched a lot but didn't find anything.
What is the best approach to create a vertical timeline kind of view?
I tried implementing via UITableView by alternating cells but that approach is very messy in terms of autolayouting (had to disbale autolayout and apply programtically when creating cell on alternate side), thereofre isn't working properly (getting stuck while scrolling). This is what I achieved:
I want to achieve something like this, which is also easily manageble:
Please Suggest. Thanks!
I would have 1 cell row with two image views. One on the left, one on the right. I think this would be easier to use auto layout.
Then you can hide the image view and labels that shouldn't be used.
I’m still learning to develop in iOS and Swift so I apologize beforehand if my question is too simple.
I have created an UICollectionViewController to show a matrix of elements. My issue is that the width of the screen is not wide enough to fit all the columns in a single row, so the excess of them are shown in another row below. Instead of this, I’d like to enable the horizontal scroll so the user can scroll to see all the columns in one single row.
I know UICollectionViewController already contains UIScrollView so I guess this should be as simple as to change a setting in the .storyboard but I couldn’t find it after many trial-errors :(
I guess it is related to the "Flow" layouts setting and that I need to handle a custom one, but don't know how exactly.
Would anyone be so kind to please help me? I haven’t attached any code because I’m using a pretty standard/out-of-the-box implementation of UICollectionViewController but if you want me to add anything, just let me know, please.
Many thanks in advance for any help!
I found the answer to my issue perfectly covered on this post:
https://www.credera.com/blog/mobile-applications-and-web/building-a-multi-directional-uicollectionview-in-swift/
It's definitely to do with your UICollectionViewLayout — that tells the collection view where everything should go. The collection view simply picks its scroll behaviour appropriately.
A UICollectionViewFlowLayout is a specific type of layout that fills one row column to the size of the enclosing view, then moves on to the next. So it does one-dimensional scrolling. Does that fit your use case?
If so then you should just be able to set the scroll direction on the flow layout.
If not then you'll need to write a custom subclass of UICollectionViewLayout that implements the layout behaviour you want.
I am working on an iOS app that has a UICollectionView. I would like to make a simple custom layout in which the middle cell on each row is slightly lower than the one on the right and left. I've been looking over tutorials and the apple documentation but most of it is for a much more complicated set up.
Is there is a quick way to stagger the middle cell. Thanks for any input!
Currently the collectionView looks like this...
I simply want the center cells shifted down by 40 pixels or so.
Subclass UICollectionViewFlowLayout and alter the response that the superclass gives so that the cells are positioned where you want them.
Here's an example of a UICollectionViewFlowLayout subclass:
https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch08p466collectionViewFlowLayout2/ch21p748collectionViewFlowLayout2/MyFlowLayout.swift
It shifts the cells left (so that they are left-justified instead of full-justified across the screen). It is not difficult to see how to adapt this to shift certain cells down.