I have a API which returns JSON:
{
"id": 1,
"name": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}
{
"id": 2,
"name": "A blue door",
"price": 13.50,
"tags": ["work", "blue"]
}
In iPad app, I need to show this in the following data table format:
id name price tags
1 A green door 12.50 home, green
2 A blue door 13.50 work, blue
I have tried the following https://github.com/brightec/CustomCollectionViewLayout but it does not work.
How can it be done?
You can create a simple table view. I created a simple example with your data. Sorry, I don't have time to add comments and the UI is basic.
Check the following example:
Show data into table view
Related
I have an issue that I have created 4 derived Products from a single part, that each part has a different Colour / Material set within it. I have the 4 Products called as PossibleChildren in my main part but when I try and bring in one of the 4 Products which ever is the first colour I pick, is the only colour that will select, so if for example I select RED for my first part, if I then pick the BLUE part it still only places the RED part. I created the 4 Products by importing this text...
"item_id","configuration"
"sub_s2_8t15","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_8t15""}}"
"sub_s2_7t58","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_7t58""}}"
"sub_s2_4t50","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_4t50""}}"
"sub_twinwall","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:twinwall""}}"
And then in the master.json part I call the 4 created Products...
"itemId": "racksystems_test:sub_s2_8t15",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_s2_7t58",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_s2_4t50",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_twinwall",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
},
I have a KEY in the sub_fronttile.json as this..
{
"key": "tileColour",
"type": "Material",
"labels": {
"en": "Tile Colour?"
},
"defaultValue": "",
"valueObjects": [
{
"value": "racksystems_test:red",
"labels": {
"en": "Black"
}
},
........
Then call the colour in my geometry like this...
AddCube(Vector3f{infillWidth-20,materialThickness,infillHeight-20});
SetObjSurface(tileColour);
MoveMatrixBy(Vector3f{20,-offset,40});
So master.json is my main part and sub_fronttile.json contains my products
Is tileColour a global parameter? If yes, then the global value is assigned on dock. If tileCoulour is not a global parameter, this should not happen unless an assignmentOnDock is used.
In order to workaround the assignment in global parameters, it might help to:
have two parameters instead, tileColour_local, tileColour_global where one is global and not visible, other is not global and is visible.
tileColour_global.onValueChange: "if (parameter.userTriggeredChange) { tileColour_local = tileColour_global; }
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 3 years ago.
Improve this question
I'd like to implement a commenting system where users can reply to others who've left comments. I'd like to display these comments in a nested hierarchy view, similar to what the reddit app "Apollo" does below:
https://i.imgur.com/JiLLsjs.mp4
As you can see, the comments are sorted in a nested format.
Here is what my API response looks like:
{
"success": true,
"data": {
"comments": {
"data": [
{
"id": 1,
"parent_id": 0,
"depth": 0,
"message": "1",
"children_count": 2,
"children": [
{
"id": 2,
"parent_id": 1,
"depth": 1,
"message": "2",
"children_count": 1,
"children": [
{
"id": 3,
"parent_id": 2,
"depth": 2,
"message": "3",
"children_count": 0,
"children": []
}
]
},
{
"id": 4,
"parent_id": 1,
"depth": 1,
"message": "2",
"children_count": 0,
"children": []
}
]
},
{
"id": 5,
"parent_id": 0,
"depth": 0,
"message": "1",
"children_count": 0,
"children": []
}
]
}
}
}
As you can see, each comment object has a parent_id (the parent comment ID), a depth (basically the "level" of the comment in the hierarchy), a children_count (the number of direct children), and children (the children comments themselves).
So with that, my questions are:
How would this best be implemented? As a table view, collection view, or something else? I assume I would create a xib for the comment view itself?
What is the best way to approach actually implementing this? How should I loop through the API response?
How do I add a margin/padding to the left side to make a comment look nested?
How do I make the cells expandable?
What should I know about in terms of memory management?
Thanks.
1- Personally would go with a tableView
2- It's a recursive operation that ends with let children: [Datum]? being empty/nil like
// MARK: - Empty
struct Root: Codable {
let success: Bool
let data: DataClass
}
// MARK: - DataClass
struct DataClass: Codable {
let comments: Comments
}
// MARK: - Comments
struct Comments: Codable {
let data: [Datum]
}
// MARK: - Datum
struct Datum: Codable {
let id, parentID, depth: Int
let message: String
let childrenCount: Int
let children: [Datum]?
}
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let res = decoder.decode(Root.self, from:data)
3- You need to limit the number of replies to a comment , as there is no screen width will fit for un-known number of replies btw it's about nested tableView padding
4- You need to play with heightForRowAt or you'll have to do some calculations for the nested tables or better fixed height with more , also more easier is to show nested comments inside another separate vc and so like facebook
5- Simply don't nest multiple vcs over each other with a count more than 2/3 also using table cells are dequeued which is a good memory performance handled automatically by system
It looks like there is no option post a message containing a table on to slack. I am trying to build a table using text formatting. In the below example the text isn't aligned because first row has text ROW1 and second row has text ROW. Is there a way to add a white space after ROW in order to align this text?
{"text" : "ROW1\t\t\t\tCOL1\nROW\t\t\t\tCOL2"}
Generally speaking, you can use Slack's message builder to test the rendering of your messages.
This being said, while I dont think you can simply "push" spaces to the right, you could use the pipe symbol like this :
"text": "ROW1|\t\t\t\tCOL1\nROW |\t\t\t\tCOL2"
Another possibility, with minor changes, is to use attachements with fields like this
"attachments": [
{
"fields": [
{
"title": "Col1",
"value": "text1",
"short": true
},
{
"title": "Col2",
"value": "text2",
"short": true
}
]
}
]
All my Passbook environment works fine (PHP/MySQL based server for pass generation and signing, and the pass download - webview based download, emailing the pass or presenting inside my app with PassKit).
The only thing that is not working is the color of the labelColor in the primary fields of a coupon type pass.
I have (in the pass.json file):
"foregroundColor" : "rgb(30, 30, 30)",
"backgroundColor" : "rgb(230, 230, 230)",
"labelColor" : "rgb(30, 30, 30)",
The foregroundColor and backgroundColor work fine, but the labelColor (presented on top of the strip image) is white, instead of the labelColor specified.
According to AppleĀ“s Passbook package reference, the labelColor is optional
"Optional. Color of the label text, specified as a CSS-style RGB triple. For example, rgb(255, 255, 255). If omitted, the label color is determined automatically."
In this case, the strip image is a clear image so, the text should be black (even if labelColor omitted and the color determined automatically), but the try appears white in the pass
Any help would be appreciated.
... e
Label and foreground colors are only applied to primary field labels and values when there is no strip image in the pass. Where a strip image exists, the text color is automatically changed to white.
There is an undocumented parameter stripColor that can be used to set the colour of the text over a strip image. This changes both the field and the label.
This parameter has been around since the early iOS6 betas. However, use with caution. Just because it works today is no guarantee it will work in the future.
I found that using the "stripColor" does change the text in the strip outside of the "foregroundColor" parameter. This is still the case in iOS 8+
Here is example of where to put the "stripColor" in the json.
passJson = {
"formatVersion": 1,
"passTypeIdentifier": "pass type goes here",
"serialNumber": "serialNumber goes here",
"teamIdentifier": "",
"organizationName": "",
"description": "",
"logoText": "My Logo",
"foregroundColor": "rgb(150,0,150)",
"backgroundColor": "rgb(255, 255, 255)",
"labelColor": "rgb(0, 0, 0)",
"stripColor": "rgb(255,255,255)",
"associatedStoreIdentifiers": [
],
"associatedApps": [
{
"title": "Name of your app"
}
],
"barcode": {
"message": "coupon",
"format": "PKBarcodeFormatPDF417",
"messageEncoding": "iso-8859-1",
"altText": "coupon"
},
"coupon": {
"primaryFields": [
{
"key": "offer",
"label": "Offer text 2",
"value": "Offer text 1"
}
],
"secondaryFields": [
{
"label": "Expires",
"value": "09/26/2015",
"key": "expires"
}
],
"backFields": [
{
"label": "TERMS AND CONDITIONS",
"value": "Back of pass",
"key": "terms"
}
]
}
}
I just create some passes and add some location, but I don't know to set text for different location. How to do that ?
You simply need to add a different relevantText key to each location entry in your pass.json.
"locations": [{
"latitude": 22.284664905736,
"longitude": 114.15818423018,
"relevantText": "Visit our ifc branch"
}, {
"latitude": 22.2864734223,
"longitude": 114.16105383063,
"relevantText": "Come see us at Star Ferry"
}, {
"latitude": 22.282069510469,
"longitude": 114.15340739122,
"relevantText": "We're here in Shelly St"
}, {
"latitude": 22.280349497127,
"longitude": 114.17643496924,
"relevantText": "Find us in Brim 28"
}],
One small point to add to PassKit's answer - you can fit approx. 23 characters of text in your relevantText string - any other characters won't fit on the lock-screen and get cut off ..