UITableView for a list of Controls [closed] - ios

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 7 years ago.
Improve this question
I am trying to understand when one should/should not use a UITableView.
I do know, if there is a table of information UITableView would be the perfect fit. But what if there are rows of "controls" ?
See the image below.
What are some of the advantages and disadvantages of using a UITableView to achieve layout above?
What alternatives to a UITableView exist for achieving such a layout?

This comes down to the question of how many controls/rows you will have and what they represent.
Dynamic Number of Controls Based on Model
A tableview is the perfect solution. The complications with having controls in a table view cell that is dynamically generated:
1) You cannot add IBActions for controls in table view cells. You will need to add a target/action to each control when the cell is generated.
2) Your action method will need a way to determine which element in your model the cell is displaying when selected (since cells are reused, controls will correspond to many model objects). To do this you need the index path in your model corresponding to the selected control. This can be done as follows (assuming a button but should work for any control):
Determine the control's position in the tableview:
let buttonPosition = button.convertPoint(.zero, toView: tableView)
Find the index path
let indexPath = self.indexPathForRowAtPoint(buttonPosition)
Then query your model for the object at the index path and respond accordingly.
Finite Number of Controls
The above is needlessly complex if you have a finite and known number of controls at runtime. In that case the above layout can be easily achieved with a UIStackView.
See StackView Documentation

Having controls in tableViews is perfectly fine.
You may want to know that tableviews have scrollable content and selectable cells, so your interactions will be slightly different than if you directly put your controls in a view.
Row selection and bouncing bounds can be annoying, as well as the delayed tap while touching inside a scroll view.
But if you need your controls to be dynamically shown depending on your settings, it can be done with the tableview data source or delegate methods.

Related

Should I reuse tableView cells when they have little difference? [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 4 years ago.
Improve this question
I just want to know which is the better way to do cell reuse
For example:
Cell 1:
Name
Detail
Time
Cell 2:
Name
Detail
Image
Time
The two cells, "Name","Detail","Time" are having the same position.
So, my questions are:
Shall I use one cell for reuse(modify constraint in runtime) or create two separate cells?
I think use two cell will have the better performance, but how to reuse the "Name","Detail","Time"'s auto layout in xib (If use code, this is easy for me, but my project use xib)
You have many options.
use stack view, then manipulating constraints is not needed to hide a element. Lets you only create one storyboard/IB instance and stack view handles hiding nicely.
use two unique cells, they can grow over time down separate paths as requirements change.
Or my preference
create cell subclass, lets say BaseCell, that loads object or
protocol that can supply name/detail/time, cell.load(xxx)
create a cell that subclasses BaseCell, say ImageBaseCell, that loads
an object that loads object or protocol that can supply
name/detail/time/image, handle image here, but super.load(xxx) will
handle the rest.
This does require individual xibs per cell subclass. However, this way, logic for handling name/detail/time is in one place, instead of several cell classes.
I would recommend for going with two separate cells. The table view datasource methods will take care of populating the cell contents rather than you handling the views inside cellForRowAtIndexPath method. Also if you're incorporating contents of varying sizes in the a cell, it is always better to go with multiple cells for cells having different contents.

what should I use to show very large static content data ? UIView, UITableVIew or UITableViewCell? [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 want to show a large amount of content with images.
It is kind of blog which contains some information with pictures.
I don't have any API, I have to show/write data manually (Hard-coded).
So, which will be the correct way to achieve this?
UIView 2. UITableView 3. UITableViewCell
For example : Seen below image, this is the sample, same way I want to impelemt. It is just some view, it contain very large data. When you scroll it will display more details.
I would recommend using multiple UITableviewCell approach with core-text ability to render text as in the screenshots mentioned.
Also, I would like to highlight that UITableviewCell is having issues in calculating auto height provided NSAttributedStrings based rendering
I think it's suitable to use UITableview with 2 custom cell one for images and the other for text , remove it's separator style and prevent selection give the label 10 margin from all directions and set .lines property to 0 , also use attributedString to set different fonts , colors to a specific range inside the text of the label
Can use tableview with custom cells. As its row height will be dynamically handled so no need to do much more complex process and easy to build.
Use UIScrollView if the content will be static (e.g. header and content). Because using UITableView will be redundant.

What is the best way to design a form layout [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
What is the best way to design a form layout, I've tried using static UITableView, but I don't know if it's a good practice when I have many cells and if I use prototype cells, it's difficult for me to interact with the elements inside the cells.
Other form is without using UITableView only a UIScrollView, but I don't know which is the best form.
In short, which is the most used method for design a form layout?
EDIT: I need to achieve something as shown in the image.
EDIT2: In the case of a CustomCell have a picker view inside, it's better that the same cell delegate from the UIPickerView or it should be the viewcontroller that delegates from the pickerview?
Now my CustomCell delegates from a UIPickerView and the options strings array and protocol methods are inside that class, that's okay?, In that case, what can I do when the array is composed of custom objects instead of strings, for example, I have an array of Persons and I need to show in the pickerview the person name, but I need to return to the viewcontroller the person's age. In that case, I have to create other custom cell that manage that array type (and another different one whenever I need it to handle a different type array)?, or is there any way to unify that to avoid having to create many of different cell classes?.
The best method herein would still be to use UITableView. You can design your own custom cells which gives you better flexibility incase the form changes in the future.
If the cells have similar kind of elements and you want to reduce your workload for the auto layout stuff you can surely go for the UIStackView inside the custom cell you are designing as suggested by Donovan.
The main reason for the usage of the UITableView is that it gives you great flexibility in terms of grabbing the indexPath for a particular row. Even if the form increases in terms of the numbers of rows it needs to hold on to, you do not need to add a separate UIScrollView to the same.
If the design for certain rows changes, while other still being of the same design, you can still use custom cell and put in a different cell identifier to the new cells and use the "dequeueReusableCellWithIdentifier" and incorporate the new design.
Hope this helps!
Table views are generally used when you're displaying data to the user of some sort. For your case how about trying a UIStackView. Here is a guide to get you started.

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 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