How to structure complicated table elements - ios

Normally tables are easy to manage , especially since autolayout can do most of the heavy lifting to determine cell sizes and so on. However, there are cases where things become a little bit more tricky like having a table of polls.
A poll in this case consists of labels with variable description lengths, images with varying sizes and a set of options for the user to choose from ( a nested table essentially ).
----Approach 1------
Break each poll into a number of cells
Pros:
Its easy to add more fields to a poll in the future, layout is easier to handle for a single cell for each element especially in the case of the nested table. If you need to fall back to manually calculating the size of a specific cell you can do it while keeping everything else on automatic.
Cons:
If you have multiple polls you need to keep track which cell corresponds to which poll, and you generally need to do some arithmetic to keep track of whats what.
----Approach 2-----
Have the poll that contains all these elements be one big cell and set the constraints between them appropriately.
Pros:
Its easy to implement, maps your model to your cell in a one to one fashion without having to multi-demultiplex your data.
Cons:
Autolayout can get hairy with nested tables. For example, for the height of the cell in this case, i used to return UITableViewAutomaticDimension until i realised this wont cut it as a nested table exists that could be any kind of size. Its quite straightforward to calculate the contentsize of the nested table, however, this would mean you would have to calculate ALL of the other elements as well as now you're returning a specific height and not automatic. Your job has become that much harder.
----Outro----
How do you approach issues like that? Approach 1, 2 or something entirely different? I've simplified the structure of the elements here to make things a bit more readable, there's more arcane stuff involved like shadowed views containing the elements you see to create the illusion of a floating card etc.
Thanks everyone.
P.S : If there's already an answer about this somewhere please point me towards that, i just haven't found much on this yet. Hopefully this post can spark some discussion on the matter and help other people in my shoes.

A straightforward alternative suggested by Paulw11 is to use sections and Approach 1. Even though this may not cover cases that have tables within tables within tables, it will suffice for what I imagine is mostly every conceivable case that has a respectable UI.

Related

Conditional formatting color scale - second highest value as maxpoint?

I have a table with values in it. I want to be able to immediately spot the cells with the biggest values. Using the color scale tool works nicely as demonstrated below
However, with my real data, there are a few cells that have huge values in it - these then raise the maxpoint so high that the formatting kind of breaks for the other values since in relation to the maxpoint, the other values are very small, making the colors among them almost indistinguishable.
I have obtained the second-highest value by doing =large(A1:C3,2) in an unrelated cell - however I seem to be unable to reference that cell in the Maxpoint setting. Is there a way?
Another idea was to manually set up a color scale that is more logarithmic in its curve but this really isn't a nice option I think. The only option that's left that I can think of is to dynamically color the cells via a script - is there already an easier or existing solution?
try like this:
=LARGE($A$1:$C$3; 2)

using excel to show Increase, Decrease and no change in Multiple colours

Looking for some help or to be pointed in the right direction. Been stuck on this for a while and the main issue is I don't even know where to start. I am sure there is a solution but my brain will not see it.
To use as an example I have a table that shows monthly results for multiple different areas:
What I want to do is in the gap along side each number is show an increase, decrease or no change, using up arrow down arrow and square. That I can do using conditional formatting my issue comes with the fact that I also want it to be multiple Colours. So it will take into account increase and decrease and whether they are in target.See below:
Atm I am copying and pasting each month. But having it automated would be amazing. The outcome would hopefully look like this:
I am hoping there is a way that I can do two things compare to the previous month and then check it against my table to see where it sits then display the appropriate symbol.
Thank you in advance for any help or a place to start.
So extremely easy to figure out once I looked at it in a simplistic way.
Firstly, I used: =IF(-SIGN(E26-G26)= 0, "n", IF(-SIGN(E26-G26)=1, "é", IF(-SIGN(E26-G26)=-1, "ê","")))
To compare the current number to the previous number and get a 1, 0 or -1 depending on if it had gone up down or stayed the same, using this it either displays é, n or ê. I then set the font on these cells to Wingdings. so they become up arrow, down arrow and a square.
Then I use conditional formatting to colour it based on the adjacent cells value.
No need for a long, complex formula
=IF(A2>A1,"t",IF(A2<A1,"u","v")) - set the font to Marlett

BattleShip Game IOS conceptual design

ok, here´s a first time noob question, sorry if that´s stupid.
I was just wondering, for a battleship kind of game, would it be a waste of memory to build a set of objects for each cell (10X10=100), with position(x,y) and state(empty,hit,missed) properties?
I was wondering if it would be better to only create an object Grid and use methods to calculate the cell positions whenever necessary (when handling cell selection with touches or drawing for example)..
The former is problematic because you may have ships that sit side-by-side or end to end and it will become difficult to know when one is completely destroyed just from the data structures you described. Two hits side-by-side could be two hits on the same ship, two hits to two different ships, or even a sinking for the smallest ship.
Go with the latter for sanity's sake.
If I was doing this, I would keep it simple, Have a 2 dimensional array, that's your 10 by 10 grid.
When someone takes a turn, calculate the position and;
if it's a miss, insert a 0 in that array cell
if it's a hit, insert a 1 in that array cell

Getting Polygons to display multiple variables using a stripped color scheme in ArcMap

I am creating a map in which i want a polygon to display two separate variables within it. Therefore I want a stripped polygon relating to both the keys from the separate factors however I have no idea on how to do this. I messed around with multiple attributes on the properties section and could get the two variables up however could see no way of making the polygon display them both.
Thank you, any help would be appreciated
This is partially manual, but you are going to have to make a separate category within one of the fields that identifies the multivariate features. You could also create a new layer that is a selection of these features. Once you have that, go to the layer properties and display the features as 'Categories - Unique values, many fields' and hit the 'Add All Values' button. Once the categories are populated select the one you are interested in and pick a hatched symbol such as 'Radiation Overlay'. Then go to the Symbol Property Editor (double-click the symbol) and modify the two layers that make up the hatched symbol. You need to adjust the color, line thickness, offset, etc. until you get it to look the way you want. Probably not as auto as you wanted, but it will satisfy display purposes.

Efficiently Computing Text Widths

I need to compute the width of a column with many rows (column AutoSize feature). Using Canvas.TextWidth is far too slow.
Current solution: My current solution uses a text measurer class that builds a lookup table for a fixed alphabet once and then computes the width of a given string very fast by adding up character widths retrieved from the lookup table. For characters not contained in the lookup table, the average character width is used (also computed once).
Problem: This works well for European languages but not for Asian languages.
Question: What's the best way to tackle this problem? How can such an AutoSize feature be realized without the relatively slow Canvas functions and without depending on a specific alphabet?
Thanks for any help.
You said you want to get the maximum text width for a column. Can't you, say, take only the 4 or 5 longest strings and get their widths? That way you won't have to find the width for all items and can save quite some time.
Or you use your cache to find the rough length of the strings and then refine that by getting the actual width for the top 4 or 5 items you found.
I don't think it matters a lot whether you use Canvas.TextWidth or GetTextExtentPoint32. Just use one of these to get the exact widths, after you used one of the methods above to guesstimate the longest/widest strings.
To those who think this doesn't work
If the poster of the original question thinks it could work, I have no reason to think it won't. He knows best what kind of strings can be in the columns he has.
But that is not my main argument. He already wrote that he does a preliminary textwidth by adding the predetermined individual widths of the characters. That does not take into account any kerning. Well, kerning can only make a string narrower, so it still makes sense to check only the top 4 or 5 items for the exact width. The biggest problem that can occur is that the column could be a few pixels too wide, no more. But it will be a lot faster than using TextWidth or GetTextExtentPoint32 or similar functions on each entry (assuming more than 5 entries), and that is what the original poster wanted. I suggest that those who don't believe me simply try it out.
As for using the pure string length: even that is probably good enough. Yes, 'WWW' is probably wider than '!!!!!', but the original poster will probably know best wat kind of string material he has, and if it is feasible. '!!!!!' or 'WWW' are not the usual entries one expects. Especially if you consider that not only one single string is checked, but the longest 4 or 5 strings (or whatever number turns out to be optimal). It is very unlikely that the widest string is not among them. But the original poster can tell if that is possible or feasible. He seems to think it is.
So stop the downvoting and try it out for yourself.
I'm afraid you have to use Canvas.TextWidth, or your implementation will be imprecise. The width of text depends on the font kerning, where different character sequences may have different widths (not just the total of individual character widths).
Me, I cut out the middle-man and use the Windows API directly. Specifically, I use GetTextExtentPoint32 with the .Handle of the Canvas. There's nothing you can do to be faster, other than caching results in some way, and frankly you'll just add overhead.

Resources