Automatically calculate cell using Swift - swift

Can anyone help me with trying to figure out how to structure my code so I can enter in a value into one cell and have other cells calculate based on that cells value. For example, I want to have a static table view with 4 cells. The first cell being a total amount and the other 3 cells will automatically calculate when a user enters data into the 3 remaining cells. The data has to be dynamic. For example, if the total cell is equal to 12.00 and a user enters 2 into one of the three cells, the numbers 5 and 5 get placed in the other two cells automatically. I am think some kind of loop but can't figure out how to structure it.

You should use a UITableView with Prototype cells, not static, so you can reload it and have dynamic values in the text fields. If you want an example, let me know.

Related

AutoLayout of Custom Accordion/Collapsible UITableViewCell

I would like to build a TableView where when the user clicks on a cell it expands to show more information. My question is how do I use Autolayout to arrange the multiple items in each cell.
Each cell will always be the same size, whether it is collapsed or not, so the sizing isn't dynamic.
The first problem I have is how to use Autolayout to arrange all the items in the cell. Before Xcode 7 I was successfully using Autolayout where I would pick a label-button-view to arrange, click Editor > Align > Trailing/Leading/Top Space, to.. etc. This is now greyed out and I don't know how to replace my old strategy.
Each cell has two rows of items. The first row shows all the time, the second only shows on collapse. Below is a picture of how the cell will look when it is collapsed:
The first row is a bit trickier because outlet1 and outlet 2 will have variable sizes. I would like 'label' to come right after label1, no matter how long or short that outlet happens to be. As arranged currently, there is a variable amount of space between the two.
What I'm looking to achieve in row 1 is basically exactly like Venmo:
Notice how 'paid' conforms to the size of the two names in the first row.
The second row has two buttons and an outlet which will always be the same size.
To sum up - how can I layout these elements in the UITableView for iphones4 thru 6S - and then how do I make this cell a collapsible cell? The construction of these cells seem to work as a system, not isolated from the whole - which is why this is a 2-part question.
is this what you want to achieve?

Why is cell increment not detected correctly in LibreOffice Calc

I have a column which I'd like to fill by selecting the top two cells and then drag down the column.
The cell contents are:
=Sheet1.B11
=Sheet1.B31
So when I drag down I expect to see
=Sheet1.B51
=Sheet1.B71
Instead, I get
=Sheet1.B13
=Sheet1.B33
Why is Calc not detecting the increment correctly? Adding more cells manually does not help.
The numbers in cell references are not single numbers which can be used to create a series in this way. In other words: The cell reference B11 is not "B"&11, but even one single cell reference.
To get references from Sheet1.B11 upwards in steps of 20, you could use INDEX like this:
=INDEX($Sheet1.$B$1:$B$100000,11+(ROW(A1)-1)*20)
Put this formula into a cell and fill it down.

Compare the values of UILables in two custom cells

I have a tableview using a custom cell per row. Per cell/row I have 3 Labels. The first label of the 3 contains a number(day). This is the same on each row. The problem is some Labels contain the same value on the next row and what I would like to achieve is that if the value on the next row is the same as the value on the current row. The Label on the next row becomes hidden.
How to do this?
There are 2 scenarios you can deal with.
The first one.
You may want that when your tableView appears it just only contains cells with different values inside the labels. In this case, like rmaddy said, you have to properly filter the tableView data source, in order to avoid repeated values, and then show the tableView.
The seconde one.
You want to show the "initial" tableView with repeated values and then update it to show only cells with different values inside the labels (maybe through an animation). In this scenario, you can filter the source data and then call [tableView reloadData] or you can detect which are the cells that have to disappear (that is retrieving their NSIndexPath) and then update tableView through
[tableView beginUpdates]
// Here use deleteRowsAtIndexPaths:withRowAnimation:
[tableView endUpdates]

How do you display a spreadsheet-like table in an iPhone view?

I need to display a spreadsheet in a view. There's no need to edit the cells of the spreadsheet, and the spreadsheet will consistently have the same number of rows and columns. (The spreadsheet cells will be populated with financial figures generated by the user in a different view)
How would I do this? A UITableView seems inadequate, as there need to be around 70-80 cells displayed in this table.
One way to do it is to write your own table cell to contain all the columns in a particular row. Then you can load the cell for each row in UITableView
If the cells don't need to be editable, they don't contain images, and the number of cells isn't large, you could just use labels or drawn text inside a grid of framed rectangles in a UIView, and display that larger view inside a UIScrollView.

How to make a table view which can be scrolled for ever?

I have a set of 100 rows, pretty similar to values which can be selected in a picker. When the user scrolls the table, I want the rows to be appended like an forever-ongoing assembly-belt. So when the user scrolls down and reaches the row 100, and scrolls even further, the table view will show again row 1, and so on. Reverse direction same thing.
My thoughts:
don't display scroll indicators (they would make not much sense, probably)
what value to return in the numberOfRows delegate method? This infinity constant?
in cellForRowAtIndexPath: simply wrap the index around when it exceeds bounds?
Many apps do this. The idea is that the beginning of the table is always the same, but you keep adding to the end, so the table just keeps growing.
Let's say you first have 100 data elements. Your numberOfRows returns 101 then. First 100 cells are normal. And scroll indicators still make sense.
If the 101st cell is displayed, you display a progress indicator like UIActivityIndicator in the cell, and initiate the process to load next 100 rows. When the data arrives, you either reload the whole table with UITableView reloadData, or you insert new cells individually with UITableView insertRowsAtIndexPaths:withRowAnimation:.
So, you just keep infinitely appending to the table. This is easier than trying to keep the table as a "window" that is always at N cells/rows and unload from the beginning of the table. If you need this sort of window, you may reconsider if this is really the best way to interact with your data.
I just finished implementing a variation of this.
Lets assume you have a 100 rows and 8 of them fit in a screen. Start by adding the last 8 rows first, then the 100 rows normally and then the first 8 rows at the end. Recenter the tableview by using setContentOffset to the first row of the 100.
When the user scrolls below the 100th one he will see rows 1-8, you can detect this in the viewDidScroll delegate function and recenter the scroll back to the first record (ensure u set the animated flag to NO when you do this). Similarly when the user scrolls past 1, he/she will see the last 8 records, you can again recenter the scroll view to show the last 8 records in the 100 row section.
This actually implements circular scrolling and the user can keep scrolling in both directions.
I haven't tried this but here's an idea. Let's say N = 100, since you have 100 rows. What we'll do is tell the tableview we have 200 rows, but we'll keep the user scrolling in the range 50-150.
Tell (the tableview) that you have double that number of rows, so for numberOfRows, return 2*N. In cellForRowAtIndexPath, always return the cell corresponding to (row % N).
Now init the table scrolled to row N (instead of 0) so that the user can scroll in either direction.
As the user scrolls up the tableview will eventually ask for row N+(N/2), when that happens send a scrollToRowAtIndexPath:atScrollPositionanimated: to scroll to the row-N. That will reposition the table back by N (ie: from 150 to 50), same cell but we'll never run off the end of the table this way.
Do the same when the tableview asks for cell at row N-(N/2) for scrolling up.
You'll have to deal with the special case where N cells fits in the view with extra room, ie: what if N were 1?