remove blank cell in UICollectionView - ios

Right now i am working with UICollection view, which i am trying to make a grid view! for loading images
i have a array with Title, which i am displaying on toolbar by using index.section.
now my problem is. if the count of section is odd number there with be an empty space in between the sections something like this.
for avoiding this i am loading all images in one section, but now as i have one section i cannot updates my title from the title array. i am running out of idea's to handle both .
do anyone have some solution or idea?

There is more than one solution to your problem:
Create an NSMutableArray and have it contain all of your array
for different sections.
Keep using sections, but create an if
condition to check if the array count is odd. In this case, you can
stretch your last cell to fit the whole width. (I used this in one
of my apps).

Related

How to structure different components within cell, rows and sections?

I am trying to understand how to structure different components within rows and sections. So my question are
1.would the top view,imageview and the components under it be separate cell or a single cell within a section.
2.What if one section does not have a imageview or a certain component. Would we just hide that view or would it be in a separate cell and that wont be called. And if hiding is the solution, how would you remove the space.
I am looking for just an abstract answer nothing specific. Just to understand how to structure views in tableviews
You pull all in one cell. For hiding any view (image, button, etc),
Put top content, image and comments on stack view.
Whenever there is no image, use imageView.hidden = true
Image space should automatically disappear.
Refer to this link for more elaborate tutorial
It depends on the preference of the developer. If you want a more flexible and easy to update/adjust view you can create a separate cell/nib file for that view. Additionally you can create it on one cell only but be careful because updating of design/view/content won't be easy.
If the imageview does not have a value I suggest that you always put a placeholder for that imageview so that the user will know that the image is not fetched.

Dynamic table cells with ability to reloadRows

By receiving data from an API, i need to compose a dynamic form. This in my head translated to a tableView with cells that have labels and input fields.
The task was completed, the cells were dynamically sized depending on the constraints, all was fine. When some input in some cell changed the following code run:
func valueOfFieldWithIDChanged(id: Int, value: String){
formFieldsTable.reloadRows(at: [indexPath,indexPath2], with: .none)
}
This updated my row and the new value was displayed properly after formatting etc.
The issue:
When the forms got bigger and spanned more space than a screenful, essentially making the table scrollable a huge issue occurred. When the table was scrolled even a tiny bit, using reloadRows made a glitchy table scroll animation.
The answer to that was essentially: DONT use UITableViewAutomaticDimension in heightForRow if you're gonna use reloadRows.
The thing is, some rows have multiline labels or need to be dynamically sized in some way or another. It seems like i have to calculate this by hand but i dont know how. Unless.. i'm missing something? Truly hope i am
EDIT: Someone mentioned in the comments that there are other ways to updating fields without reloading the rows. This might be a way to go about it but i dont know what those other ways are

Accordion for UIView and SubViews in Swift 3

I'm trying to build an accordion style ( expand/collapse ) list in IOS/Swift 3. Was confused on which approach to follow like a static UITableView ( since my sub divisions have different types of Ui Controls in the cells ie some have checkbox ,spinner, textview etc. with labels to show configure a list of different Valves) , UIView with nested UIViews sections with an option to clip views . But both have been messed up with without any success.
Illustration
http://imgur.com/a/Bs9SF
Below are the links I followed
https://github.com/justinmfischer/SwiftyAccordionCells
http://www.appcoda.com/ios-static-table-view-storyboard/
https://github.com/Weebly/TableSchemer
https://github.com/Alliants/ALAccordion
Any other approach without UITableView?
Please help . Thanks in advance .
Static vs dynamic table will depend on your data source. Does your data source for your table change? If so you'll want a dynamic table, if not then you can design it out in a static one.
As for the accordion feature, what I've done in the past is to add a tap gesture recognizer to the header view of each section. When the tap is detected I change my datasource and reload the table view. What happens is that number of rows for section is called on reload, and I return 0 so that none of the rows show. When tapped again you can go back to showing the normal number of rows.
To get the animation you need to use delete rows with index paths and animate it.

iOS Swift How to Extract Strings from All Selected Rows in a TableView

I want to loop through a TableView and extract the text from all the selected rows. I suppose I "could" create and maintain a special array that is updated every time a row is selected/deselected using the didSelect/didDeselectRowAtIndexPath methods. But creating a separate array seems like an extra step. Is there no way to let the TableView itself serve as the array and then simply loop through it and get the selected rows? What would the code look like? I'm new to Swift, so this might be a silly question.
Part of the problem is that cells are supposed to be reused, and when used this way it is not possible to loop through them all. You could get around this by using a unique reuse identifier for each cell, such as the indexPath itself or some underlying unique id in your model. Then, you could indeed loop through all cells and retrieve whatever state you desired from each.
You would, however, find your application crushed under the weight of too many cells being instantiated and kept in memory. If you don't have many cells you won't be killed, but try it with a big data set and your app will enjoy a very quick death.
It is far more efficient to store one array with a bunch of id's than a large number of memory-intensive UITableViewCells.
As mentioned in comments, you should work with underlying datasource, not the table itself.
For example if your table shows rows from Array, it is way more faster to retrieve strings directly from that array than creating UITableViewCells and get strings from them.
Get indices of selected rows using UITableView's property indexPathsForSelectedRows.
Query datasource for each row.
As has been said the tableview only handles displaying, your datasource is what powers the data shown if you think about it.
Plus as said before the tableview dequeues cells as they scroll on and off the screen.
The best way to achieve what you want is to add a property to your datasource for each element that will allow you to filter out the select properties easily.
How are you storing the state for each selected cell currently? As this is the same functionally you would use to be able to generate your selected text array.

It's possible to customize UICollectionView for displaying few sections like one?

I have three different kind of objects that I want to display in collection view.
But if in section 0 is only 1 element, next section starts from new column.
Can I tell to the layout that it should show items in different sections one after the other with no breaks?
Sure, but if that never changes, why not make two side-by-side sub views?
The left one contains the one element, the right one contains the collection view you originally planned to use.
That way the layout doesn't need to know how to work around the left element.
Additionally, you can use one data source. Make datasource[0] the left one,
And use datasource[indexPath.row +1] for the whole cellForRow..... method.
Just remember to set total cells in the collection view to [datasource count] -1
My solution is to use 1 section and create methods for determinate abstract sections.
In addition, I add -infoItemsCount, -visibleItemsCount and -hiddenItemsCount and same methods for generating cells and other.

Resources