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
So I am loading information via JSON to a table view in my iOS app. When you click on one of the table cells, I need to get the "id" of the story in the database, from the cell clicked.
I haven't tried anything yet, because I don't know where to start.
If you don't know where to start, start at the beginning. How 'bout a tutorial on using JSON in iOS? The Ray Wenderlich website has great tutorials. http://www.raywenderlich.com/5492/working-with-json-in-ios-5
OS 5 has some new built-in APIs to make it really easy to read and
write JSON.
If you don’t know what JSON is, it’s a simple human readable format
that is often used to send data over a network connection.
For example, if you have an array of three strings, the JSON
representation would simply be:
["test1", "test2", "test3"]
If you have a Pet object with member variables name, breed, and age,
the JSON representation would simply be:
{"name" : "Dusty", "breed": "Poodle", "age": 7}
It’s that simple, which is why it’s so easy and popular to use. For
the full spec, which can be read in just a couple minutes, check out
www.json.org.
You must be feeding the table with data from somewhere, so let's assume that that's an NSArray of Story objects.
When you select a row in a tableView, the didSelectRowAtIndexPath: delegate method will be called. The tableView supplies the indexPath of the selected row.
An NSIndexPath has two properties - section and row. The indexPath.row value of the selected cell will correspond to the index of the element of the NSArray from which the cell got the Story object. So if you want to retrieve the Story for the tapped row, you'd use [theArray objectAtIndex:indexPath.row]
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
Suppose there's a website that has a list of details of some companies, for example, name, HQ area, turnover, etc. How do I scrape that data and fill it into different columns (like name, turnover) with each row having the details of a separate company?
Google Sheets allow you to import html tables or list with the IMPORTHTML(url, query, index) function.
For example, using the Wikipedia page List of largest companies by revenue as an example.
We want the data from the main table, so the first thing that we have to do, is to know what index it occupies in the page. To do this, we can use document.querySelectorAll('table') or $$('table'), as you can see from the result, the table that we want is in the position 5 of the array, so inside our google sheet we can use:
=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue","table",5)
From here, you should change the query parameter to list and find what index it occupies within the page using the method described above. In any case, you could always use IMPORTXML(url, xpath_query), and knowing the XPath of the information, you could come up with a similar solution.
So I have did some RnD regarding this already and didn't found anything that will help me to solve this one. So the problem is consider and paper pattern of MCQ question paper and I want to store the each question's answer and at end I need to convert it into JSON data to post it to server. So here all sections are my questions and all rows are my respective answers. For now I've rendered UI and now I'm just concerned about how I can store this data against each question. Also suffering from common problem of repeating dequeue cells. So request to anyone who can guide me in correct way.
So storing each selected index of UICollectionView in [[IndexPath]] array solved this problem for me. Where I initialized this array on view didLoad as per the count of my dataSource array. So my multi-dimensional arrays's outer loop will hold an section per count and inner loop will hold an row count. e.g. [[1,0],[1,2],[3,4],[4,1]] .
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have been following the tutorial for creating a UISearchController using https://www.raywenderlich.com/113772/uisearchcontroller-tutorial
Everything is set up and working perfectly. I have two categories in my dataArray: Borough and Neighborhood. I set up my searchBar to only look into the values for Neighborhood. I created buttons for the different boroughs and what i'm hoping to achieve is when the button is pressed it will show all the possible values for that borough, but I can't seem to find anything to do this
I believe what you are saying is that you want to search for a text value entered via the search bar in the Neighbourhood values and to specifically look for the Neighbourhood in a given Borough. Correct?
If that is the case, all you'd have to do is modify your search condition. If your search condition is currently something like (to borrow from the rw.com tutorial):
return row.neighbourhood.lowercaseString.containsString(searchText.lowercaseString)
Then you'd have to modify the condition to include a check for the Borough name too - and here, we'll assume the borough variable contains the Borough name that you selected via button press:
return row.neighbourhood.lowercaseString.containsString(searchText.lowercaseString) && row.borough == borough
That should return only array values which have the specified Neighbourhood name and are in the given Borough. If that is not what you wanted, then you might want to provide a bit more detail such as the structure of the data array, how the Neighbourhoods and Boroughs are linked, and perhaps even a screenshot of the UI so that we can see how you select a Borough in the UI.
This question already has answers here:
Load UITableView From CSV Database File?
(2 answers)
Closed 8 years ago.
I currently have a list of 1,000 records that I would like to use to populate into a Tableview but I am not sure how to go about doing so. The list is currently in a .txt file. Does anyone have any suggestions as to how to go about populating the table view with this list. Any suggested line of codes would be greatly appreciated.
EDIT: Updating initial question to provide more detail.
Say I have a list of all of the countries in the world that I want to load into a tableview. I have the list in a text file. Is the best approach to insert all of the countries one by one into an array or can I just link the data source of the table view to the .txt file to load the data? Maybe there is another way that I cannot think of. (Sorry if this is not enough detail, I am new to Objective C)
Just read the file using NSFileManager. Once you have the file into a single string object, then you can check this answer in how to split an string obtained from a file.
How to split newline from NSString in ObjectiveC
Then once you have this into an array you can fill your tableView really easy using the UITableViewDataSource Delegate Method
cellForRowAtIndexPath:
just assign to the cell.textLabel.text the value for the array at index indexPath.row provided by the method.
cellForRowAtIndexPath:
If you can provide some code and the example in how your file looks you could receive more help. Your questions is vague but what I just answer might help to clarify your ideas
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
im new to iOS/xcode app and have a question.
If i make a form with "name" "age" "date now" how/where is it saving the info and how do i make new items ?
Have tried to search google for "xcode saving item to list" but its not what im looking for.
Can someone help me with a link to a tutorial or the name function that i need to look at.
So i can read/learn about
- save function
- show the saved items in a list.
- get one or more saved items to another page/view in the app.
First you need to deal with getting notified when the text in each field changes. This is done by using the delegate methods of the text fields (<UITextFieldDelegate>). In particular, textFieldDidEndEditing: will allow you to grab the text when the edit is complete.
Once you have the text, you need to store it somewhere. This could be in a dictionary, or, if you want to display in a list, it could be in an array.
A dictionary is easier if each of the text fields means something different. Then the keys of the dictionary represent the meaning.
An array is easier if it's just a list of arbitrary text. The issue here is how to know that you haven't got duplicates. In this case it can be better to have a submit button which loops over all of the text fields in order and adds the text from each to the array.
Once you have the text in an array or dictionary you can save it to disk (writeToFile:atomically:) or use that as the source data for a table view.