Collapse sections in Objective-c [duplicate] - ios

This question already has answers here:
Expand/collapse section in UITableView in iOS
(17 answers)
Closed 9 years ago.
I am doing an application form in my app and I want to make something creative, so I thought of having the form components in sections (like the following images), and do a collapse and expand affect on them.
Is there is any class or something which could help me implementing this or I have to do it manually?

I used to take advantage of a UITableView and the methods
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
and
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
to simulate and expand/collapse behaviour.
Refer to the documentation for more details.
I've used then selectable section headers (either via UIButton or gesture recognizers) to let the user expand/collapse.
There are also a lot of tutorials out there that are quite explanatory, using different techniques:
Collapsable Table View for iOS
Expandable/Collapsible Table For iOS
Finally you can take a look to this control that should provide the functionality that you are searching for:
UIExpandableTableView

Related

UITableView vs UICollectionView for list display

I need to display a simple list where each cell has a title and subtitle and an accessory view. Height of a cell may be variable depending on subtitle length. This was easy to display using UITableView. But I saw a more modern way is to display such a list is UICollectionView with list configuration. There are a number of videos on list configuration & diffable data source and number of tutorials as well on the same but what I am trying to understand is if Apple is telling developers to move to UICollectionView from UITableView (which some experts surmise is going to be deprecated given the new APIs). So my question is whether one should abandon UITableView to display such a list mentioned above, and if UICollectionView is really a replacement for UITableView?
Apple started killing UITableViews years ago, likely 5 or so. They're still here and still going strong. UITableViews will still work and there's absolutely no reason for you to drop them and replace them with UICollectionViews.

Is it good practice to ensure cellForRowAtIndexPath doesn't contain cell view modification code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I came upon this thought recently when I was working to add a 'dark/night' mode to my app.
Regularly in cellForRowAtIndexPath I would of course 'connect' my datasource to my newly created/reused cell.
Setting the cells data/strings/values etc, ready for display.
However, whilst cognisant of MVC, I myself, would sometimes set cell background colours or some other cell subview view related property (animations/colours/text style). - I'm working if this is truly a bad coding style?
During my work to create night mode, I moved ALL code related to view modification (colour/style/aesthetic) into each view class.
Then upon a reload of my tableView, I setup up each cell and finally call their new function to layout their aesthetics - which now lives inside the cell class.
Ergo, my cellForRowAtIndexPath has a single call to the cell instance to change its look and feel, and the rest of the code is purely setting data on the cell.
Is this the pure MVC approach?
Is this good practice?
Is it acceptable to be calling my tableView's reload method in order to trigger a call to update the cell as needed, whenever my viewController wants to change look and feel, or should I be keeping a reference to each cell separately?
The answer to your question is pretty subjective.
On my opinion in most cases the outlets of cell should be private to the cell's class, and not expose unneeded info to the viewController. I prefer creating several methods within the cell's class such as: func populate(_ with: SomeDataType) - for populating the cell. This way the cell is much more encapsulated and reusable.
Is it acceptable to be calling my tableView's reload method in order
to trigger a call to update the cell as needed, whenever my
viewController wants to change look and feel, or should I be keeping a
reference to each cell separately
Yes it is acceptable, in fact there are pretty rare cases that you need to keep references to reusable elements, such as UITableViewCell's instances. Please take a look at the section Reloading the Table View from the Apple documentation or func reloadRows(at: [IndexPath], with: UITableViewRowAnimation) link
EDIT 1:
I feel like you can benefit from going trough this tutorial: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/CreateATableView.html
The main goal is: Try to understand what is "reuseIdentifier" and why UITableView reuses cells instead of creating new views every time that cell should be displayed. Once you get this, you will understand why saving reference to tableViewCell is tricky.

How to customize a UITableview's index look? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
http://imgur.com/rxVYsV2 - reddit's index
I want to create an index similar to the one in reddit's app, especially adding icons to it and having it highlight the letter(see link for picture).
Any suggestions for how to do it(in xamarin ios)?
Since, you didn't ask for code, I'll just help you get started. :)
Use a UITableView to create a row, a cell would be like
Add another UITableView to create the side listing, with just an alphabet as cell. Something like
Now, on selection of any row from the second UITableView, modify the highlight and scroll the left UITableView accordingly. As well as on scroll of left TableView, change the highlight according to the first alphabet.
UPDATE
For StoryBoards follow the following steps:
Drag and drop two UITableViews in StoryBoard, place and resize them however you want (according to the layout you want), apply constraints.
Give each StoryBoard a reference like you do for other elements such as buttons etc. or give them a Tag.
In your ViewController make two Nested Classes, two of them for 1st TableView, one inheriting from UITableViewDataSource and other from UITableViewDelegate. Override the mandatory methods (link).
Now once you have the classes done, assign them to your TableViews like
//With Tag
UITableView myTableView1 = (UITableView) this.View.ViewWithTag(1);
myTableView1.DataSource = new MyTableView1DataSourceClass();
//OR
//With reference
myTableView1.DataSource = new MyTableView1DataSourceClass();
myTableView1.Delegate = new MyTableView1DelegateClass();
Please look at Create UI Objects for more help with making objects.
Please upvote and mark it as the correct answer if you feel it is. Besides, let me know if you need more help. Have a great time coding :)

How to have different elements in collection view? [duplicate]

This question already has answers here:
Displaying two different cells in a collection view - Swift 2.0 iOS
(2 answers)
Closed 5 years ago.
so I try to have collection view but been thinking is it possible to have different element in each cell view? For Example: in the first cell I have the whole cell covered by UIImageView while some specific cells only got UITextView.
Here's an example that I'm talking about, Medium iOS App.
Create several prototype cells, each formatted with whichever UI elements you want, and dequeue the appropriate cell for each different type of data you want to display.

How can I build an UITableView like App Store? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I whant do build an table view like App Store.
eg:
As we can see, App Store app enables the user to drag the rows down and the header keeps on top...
and ... when you slide up the rows, table's the header moves out the screen...
and its possible to slide the heander like so...
Here ive create an projec that aims to accomplish that.
source
If someone can help me I appreciate it.
Thanks a lot!
*
You aren't clear about what behavior you are looking for. Do you want the header to stay or not? You have also not shown any code, so we don't know anything about your table
here's some things found by simple search:
link
That behavior is only common when the UITableViewStyle property of the table is set to UITableViewStylePlain. If you have it set to UITableViewStyleGrouped, the headers will scroll up with the cells.
link
Actually the tableHeaderView scrolls with table. This is not the case for section header views. If you have only one section then you can have the header view as tableHeaderView.
table.tableHeaderView = aUiView;
If you have more than one sections and all of them have their own header views, then you have no choice than leaving the header views behave in their own ways. Or, you can imitate the header view by making/configuring/customizing the first row of each section look like header view and remove the actual section header views.
link
I think the best approach would be to use a plain UITableView with Header and Footer set, and "skin"/theme your custom UITableViewCells to look like grouped UITableViewCells.
you'd might want to have a look over here for some pointers on how to achieve this.
*
The cells you are referencing are table and section headers
You can include a custom header for every table section by implementing the UITableViewDelegate method
tableView:viewForHeaderInSection:
There are equivalent properties and methods for the table and section footers. (this is a good reference)
Create custom UIViews to assign to the headers and footers.
For the Horizontal scrolling behavior, you should place a TableView in the header/footer and rotate the table by 90 degrees; then in the cell of the rotated table, apply the rotation in reverse to the actual content. Now you have a cell that displays horizontally scrolling images etc.
In the code for the header/footer, create a TableView and transform the table
self.horizontalTableView.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
Then, in the cells of this table, you apply the transform in reverse on the content of the cell.
CGAffineTransformMakeRotation(M_PI * 0.5)
Voila, Horizontal Scrolling (see this tutorial:http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2)
You are referring to UITableView as well as UITableViewDataSource and UITableViewDelegate classes. (easier than it sounds) They work together to create dynamic table views.
UITableViewDelegate
Serving as a table's delegate means you provide answers to requests about the layout of the table and about actions the user performs on the tableView. Layout methods include the tableView asking about the height of rows, headers, and footers, what the buttons should look like, etc. Action methods include the user selecting a row and beginning and ending the editing of a row.
UITableViewDatasource
Serving as a table's "datasource" means you provide data for the sections and rows of a table and you act on messages that change a table's data. The "datasource" is asked for the data for a cell when the table is drawn, is told that the user has asked to delete a row, and is told the new value of a row that the user has edited.
There is a great tutorial on tableviews treehouse.com seen "Here".
Don't take the title literally just choose piece by piece the lines of code you can imagine using for your application! It even covers the feature you outlined in which the alphabetical header is displayed while scrolling using the tableViewDatasource and tableViewDelegate classes.
Also there are probably great repositories on "github" (didn't they just receive 100 million dollar funding?) Try finding or 'hacking' some of there code to make it easier.
Nice images BTW. Very high quality

Resources