I have this JSON file (the parsing OK, the problem is displaying the contents as I'll describe here) that I need to display in separate UITableViews:
{
"Programs": [
{"link1": "http://www.myWebSite1.aspx",
"program name": "Live Show at 9",
"speaker": "Dr. Speaker 1"
"day1": "Sunday"
"day2": "Monday"
"day3": "Tuesday"},
{"link2": "http://www.myWebSite2.aspx",
"name": "Dr. Speaker 2",
"speaker": "Live Show at 10"
"day1": "Sunday"
"day2": "Monday"
"day3": "Tuesday"
"day4": "Wednesday"}
]
}
The user will make his first choice based on the program/speaker, then a second UITableView should pop-up presenting the days of the week for him to choose from. So, this second UITableView will display the contents of day1, day2, day3, etc...
How can I make such a subdivision, with the contents of this JSON file? Thank you!
You need to declare jsonArray of NSDictionary in new UITableView Controller class and then synthesize it. Fill up that array and new UITableView pass this array in cellForRowAtIndexPath. For more details go through the link (for just idea)
http://gauravstomar.blogspot.com/2010/06/uitableviewcell-tableviewuitableview.html
Related
I'm a senior Ruby developer, and just getting into Swift and iPhone development, but can't seem to make heads or tails of where to begin with answering my own question. My apologies ahead of time if I sound extremely newb!
My goal is to take a set of data ( in Ruby, it would be a hash or JSON ), and form x views from it. For example, the data might be :
my_page_info = {
{
title: "Page 1",
content: "Blah blah blah",
additional_info: "Some more blah"
},
{
title: "Page 2",
content: "Blah blah blah",
additional_info: "Some more blah"
},
{
title: "Page 3",
content: "Blah blah blah",
additional_info: "Some more blah"
}
}
Side Question.. What would be the best way to write that kind of information in Swift? Assuming it wouldn't be in JSON..
Then I'd assume, it would be proper architecture to use just one view in the UI Builder that would represent all available data in this array. Where my_page_info would populate 3 different labels defined as #IBOutlet's arranged in my UI View Controller, and then interpolate the values.
Lastly, I wanted to have a back and forward button that would allow me to navigate these items. I looked everywhere for such a system icon, but it seems like it doesn't exist. At least not within the UI Builder. I imagine it can only be done programmatically, and then I'd have to import my own images to represent those buttons.
Would anyone know any part of my question, or direct me in the right direction?
Thanks!
From Airspeed Velocity's answer to my question, you see that a struct would be the way to go for your data:
struct Page {
let title: String
let content: String
let additionalInfo: String
}
var myPageInfo = [
Page(title: "Page 1", content: "Blah blah blah", additionalInfo: "some more blah"),
Page(title: "Page 2", content: "Blah blah blah", additionalInfo: "some more blah"),
Page(title: "Page 3", content: "Blah blah blah", additionalInfo: "some more blah"),
]
Note the removal of the underscores from variable names.
Then, I think you would want a tableview, where you set up a single prototype cell in Interface Builder with fields for each corresponding field in your data.
Edit: you probably just want the title in the cell and you would pass the other info through a segue (see below) to the page where everything is laid out all nice.
Then your cellForRowAtIndexPath method would look like:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("pageCell", forIndexPath: indexPath) as! PageCell
cell.titleLabel.text = "myPageInfo[indexPath.row].title"
cell.contentLabel.text = "myPageInfo[indexPath.row].content"
cell.additionalInfoLabel.text = "myPageInfo[indexPath.row].additionalInfo"
return cell
}
Your prepareForSegue method in the tableViewController would pass the values for the data selected to the ViewController that you set up to display the info.
I'm not sure what you're looking for in the last part, but if you use a navigationController, you automatically get a Back button (which in your case would go back to the tableViewController)
Maybe this is overkill, but I am trying to
1. open a Modal window, when a link is clicked in UI-Grid
can be done by modifying http://ui-grid.info/docs/#/tutorial/110_grid_in_modal
2. Put a (ui.bootstrap.datepicker) inside the Modal
3. Retrieve the chosen date
4. update the Date Cell in that UI-Grid Row
so, Is Ui-Grid 'well suited'/'can do this' given the above requirements
tia
Nope, not overkill. You can do this with UI-Grid pretty easily. There's a guide on how to do hook up modal editors using Angular Schema Form here: http://brianhann.com/create-a-modal-row-editor-for-ui-grid-in-minutes/ (caveat: I'm the author).
I've also created a new plunker that uses the angular-schema-form-datepicker library to show how you might do this: http://plnkr.co/edit/7t3BI2AUcnvNfav78Btr?p=preview
(plunker has been throwing 404s for files that are part of a plunk so you might have to refresh it)
The main things you have to do are set up your object schema:
scope.schema = {
"type": "object",
"properties": {
"myDate": {
"title": "My Date",
"type": "string",
"format": "date"
}
}
}
Using the same property as your column Defs:
columnDefs = [
{ field: 'myDate', name: 'My Date' }
]
And specify your date format in your form:
form = [
{
key: 'myDate',
format: 'yyyy-mm-dd'
}
]
Ok so I'm finding this insanely difficult to find for something that is done a lot. I'm struggling to find a way of putting the newest YouTube videos from a user into a UITableView.
I've tried this but it's out of date and I gets heaps of errors: http://code.google.com/p/gdata-objectivec-client/downloads/detail?name=gdata-objectivec-client-1.11.0.zip
Aside from using a UIWebView, are there any good tutorials, that work, on putting YouTube videos in a UITableView?
Let's take an example.. for Nethfel user; click on his playlist; in the link bar you will see "http://www.youtube.com/watch?v=4nx7g60Ldig&list=UUANsW00CkQnNnnUyuC1cygw"
now .. we take the playlist "number" UUANsW00CkQnNnnUyuC1cygw
and.. we will make an JSON request..max 50 results
http://gdata.youtube.com/feeds/api/playlists/UUANsW00CkQnNnnUyuC1cygw?v=2&alt=jsonc&max-results=50
You can replace JSON with JSONC - you will se minor changes in your results;
This will be your request at the beginning of your app
Now we must "interpret/translate" the next result:
{
apiVersion: "2.1",
data: {
id: "UUANsW00CkQnNnnUyuC1cygw",
author: "Nethfel",
title: "Uploaded videos",
description: "",
thumbnail: {
sqDefault: "http://i.ytimg.com/vi/4nx7g60Ldig/default.jpg",
hqDefault: "http://i.ytimg.com/vi/4nx7g60Ldig/hqdefault.jpg"
},
content: {
5: "http://www.youtube.com/p/UUANsW00CkQnNnnUyuC1cygw"
},
totalItems: 17,
startIndex: 1,
itemsPerPage: 50,
items: [
{
id: "UUGCa8nZNU7uOfDF3zV9AxkJtJSuX5gHGI",
position: 1,
author: "Nethfel",
video: {
id: "4nx7g60Ldig",
uploaded: "2011-11-02T12:32:03.000Z",
updated: "2013-01-07T18:26:41.000Z",
uploader: "nethfel",
category: "Howto",
title: "iOS Passing Data Between View Controllers Technique 1",
description: "This video discusses one of the most basic techniques for passing data between view controllers in an iOS application. This technique uses storing a local iVar in one class and passing it to the second class about to be displayed on the screen. Although this is a very simple example using an NSString, it can be applied using any other type of data as well - whether it be a collection or a custom data model object.",
thumbnail: {
sqDefault: "http://i.ytimg.com/vi/4nx7g60Ldig/default.jpg",
......
You have all the elements: title, thumbnail, link to page, etc...
you need to PARSE (extract) this JSON response.. put it in an TableView..
at click on cell, open a new "Detail" page.. were you can have LBYouTubeView for iOS
If you can get a YouTube video to play in a UIView, you can embed that in a UITableView controller cell.
I have 12 Buttons with 0-11 tagged. When the user clicks the button the tag is inserted into the first of 12 label outlets. I want the next clicked button to automatically insert its tag into the next available outlet. As of now the tag simply adds itself to the first outlet. I have tried a variety of fixes, but to no avail.
This is my implementation thus far:
-(IBAction)enterNumber:(id)sender {
cell1 = cell1+(int)[sender tag];
label1.text = [NSString stringWithFormat:#"%i",cell1];
}
My problem is getting the next IBAction to display only in cell2 (I assume this help will lead me to use the fix for cell3-cell12. None of my books' suggestions provide suitable processes to my limited knowledge.
Edited after Danillo
I hadn't considered the IBOutletCollection, I hadn't heard of it! I will certainly try to use it. For the others who wanted a clearer question to my problem I will attempt represent part of the screen that the user will interact with. The top numbers are fixed buttons. The bottom squares are where the clicked top buttons' tags are logged sequentially to the series. I just clicked (4). I would like the next click of any top button to be logged into the second bottom square, but what is happening is that the integer is being added to the integer in the first box.
(1) - (2) - (3) - (4) - (5) - (6)
[ 4 ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ]
It sounds as though what you are trying to do is provide content sequentially to a series of labels. If that is correct, this is the approach I would take:
iOS 4 and later supports outlet collections, which are exposed for your use as arrays filled with whatever objects you've assigned.
So, just as you've tagged your buttons, tag your labels. Then, in your .h file, declare an Outlet Collection like so:
#property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *labels;
Control drag each label to wire it to that outlet collection.
Then, when it's time to assign content to a label, iterate through the collection:
for (UILabel *label in self.labels)
{
if (label.tag == whateverIntYouCareAbout)
{
//Do stuff
break;
}
}
From what you said "but what is happening is that the integer is being added to the integer in the first box." I believe your problem you are able to display the number in the first label only. This is because in your method you are setting the text for the label as label1.text = someValue; using cell1 So it is the label1 which is always updated. You should get the label for the corresponding tag of the button. For example if your tag is 3 then you should change the text of label3,if its 7 then change the text of label7. Also make sure if your cell needs to be changed accordingly. This is what I understood from what you mentioned. Correct me if I am wrong.
I am trying to display dynamic values read for a store as options within a filteringSelect widget in my DOJO Data Grid. The values are getting populated as expected however, I am unable to display a default value when the grid loads, right now it shows up as "..." on single click, I am able to see a drop down.
Below is the location of the sample code:
http://jsfiddle.net/R64bE/2/
I want to iterate through my "myStore" in the code above and make the item with label = 'Y' as the default for that filteringSelect.
I want the default value displayed as soon as the grid or filtering select is rendered. Any pointers or sample code will be of great help.
Glad that I was able to fixed it too..Below is the code in case anyone wants to achieve something similar.
Working code with Default value
Basically all I had to do was send a default value for that field/cell in the first json I created.
jsonStore = new dojo.data.ItemFileWriteStore({
data: {
"identifier": "identify",
"label": "description",
"items": [
{
"identify": 123,
"description": "Project Manager",
"billingMethod":"Sample"},
{
"identify": 234,
"description": "Developer"},
{
"identify": 536,
"description": "Developer"}
]
}
});
Notice that all I had to do was add a value for that column in the json, i.e., for Billing Method Column, I added "billingMethod":"Sample" and it picks it up from there.
Cheers