iOS unread cell icon - ios

I am trying to figure out the best way to implement the blue dot like the Mail app for unread cells. I have the blue dot but I am just trying to figure out the logic behind it. The table is populated by an xml file. Right now I have it set as so, when the parsing method is called, it sets a boolean to NO within the data object. Then when the tableview populates itself, if the boolean is NO, the image is displayed, and then during didSelectRowAtIndex, I then set the boolean to YES and the image disappears. The problem lies here, every time I refresh the table, the xml is re-parsed and the instance variable is reset to NO and the user is informed that the cell hasn't been clicked. How do I fix that? What's the best logic around it?

Instead of re-parsing the XML each time you refresh the table, parse it once and then save the data (or an array of dictionaries, or whatever) it parsed out into as a variable within the object.
That way, the state of the "read" blue dot or "unread" will persist between table reloads.

Michael Dautermann is making a good point in his answer. For your situation, where the feed is often refreshed, you can keep a set where you keep track of the read elements by storing their ID's there (whatever they are). Then, in your tableView:cellForRowAtIndexPath: method, you just check if the current element's id exists in the set, and don't show the "new" image if it does.

Related

How to show a list of items without a tableview which changes when the input changes

i know that the question sounds weird but i couldn't find a better way to put it or any solution online or with my current knowledge. I currently use a view controller + a table view where user enters a list of elements to filter my database (core data) and when he clicked the search button i fill tableview with filteredContent.
Now the question is this.
how can i show this filtered content simultaneously in the same viewController where user enter the input?
Is it possible? If yes how?
Assuming the user enters the filter via text field, make the view controller the text field's delegate and implement shouldChangeCharactersInRange:.
Each time the input changes, apply the search as if the search button was pressed.
But it seems the real question is how to do this without a vc transition. The answer is either convert to an NSFetchedResultsController, which does this kind of thing for a living, or do it yourself via the table view datasource methods.
If the latter, you'd keep an array that holds filtered search results. As the user enters search terms, you search core data, place the results in that array, then reload the table view. The datasource methods base their answers (numberOfRows, cellForRow, etc) on that array of filtered results.

UITableView with input fields - How to keep values while going to detail view and back

having a bit of panic and really really need some help with this!
I'm making an app to fill in forms. The layout of the forms are created on a web server, and then the ipad app syncs with it, copies the form database, and then runs it locally.
One type of text field is a UITextView where the user can input text either by writing directly to the field, or by using one of many pre-defined texts (also defined on the web server).
To use a pre-defined text, the user touches/selects the tablecell that is containing the UITextView, and then a category-picker-view is pushed on the screen. On selection of category, the user gets a list of texts, and upon selection of text, the user gets a simple uitextview to edit it before insert. With a save button, the user then gets moved back to the original view where the chosen text is now added.
Flowchart:
root view with input fields-> category picker -> text picker -> editor
/\ |
'------------------------------save text------------------------'
The problem is that when any other view loads, all other input fields are emptied! The value of the selected field is passed via prepareForSegue, so that one is kept.
I have a save function which saves all fields to the database. I tried to put a call for it inside the prepareforsegue call, but it either crashes or does nothing.
Question: Where could i put the save function? Could/should I do it another way? Thought about putting all tag's values in a dictionary inside my appDelegate instead of running the save-function, but how could i update it every time an input field is edited?
Also - would putting the categorypicker etc in some kind of popover/modal/popup-view instead of the push segue prevent the values from clearing? I've got no experience from such views, could someone give a good starting point? (perhaps a good tutorial rather than heavy apple docs :)
I have a deadline for this tomorrow, with LOADS of more things to complete as well, so I'm very very grateful for ANY help!!
Thank you for your time!!
/Dave
I think your problem is caused by an absence of a model (in terms of the model-view-controller pattern). A model that represents your form data (e.g., custom object, NSArray, NSDictionary) should be updating the view and should be passed in prepareForSegue, not an input field's value.
Specifically, create a new property that maintains the latest data. When the user makes an edit or selects a category for some field, update the model. Then, when you return to your form view controller, use viewDidAppear to update the input fields to their latest values.

"Compact" view in iOS

I have a view in iOS (iPhone) that have multiple components, organized in sort of a stack way (one in top of the next). Those are user account properties, some could be blank.
So, I have in my view the components layout like this:
UITextField1 (Name)
UITextField2 (Location)
UITextField3 (Age)
UITextView1 (Bio)
UITableView (user entries).
Some of the fields could be blank. Instead of having blank spaces for the blank fields I would like the next field to move upper.
This is like this question of flowlayout: What is the best/easiest way to create 'flow layout' type layout in iOS.
I can only see two ways of dealing with this:
Creating a function that traverse all the UIViews and determines which ones are blank and move the following upper.
Creating a UITableView and use different cell heights for cells whose content is empty.
Ideally there would be a component, but I cannot find it (basically some sort of stack/flow layout).
Anyways, I believe that I am going to implement the option #1 above, but I don't know if there is an "standard" way of accomplishing this (I honestly don't even know the proper term to look for this feature).
Thanks.
I would lean more in the direction of your second choice by using a UITableView but not the way you propose.
This would be my approach using a UITableView:
Create a UITableViewCell (or custom cell) for each one of my
components and assign a tag value to each, we'll use these later. You can do this in viewDidLoad.
Add code in numberOfRowsInSection to check to see which fields have
data values present. Return the total count of the number of fields
with data values
In cellForRowAtIndexPath again, check if data exists for that field
If so, check to see if the cell created in step one has already been created or not (if not, create)
If not, increment a counter of some sort to increase your tag value and find the next field that has a value. Once found, use that "tag/index" number to "return" the proper cell.
In the end, you have a UITableView only displaying the fields with data.

Content tagging/bookmarking by users

I have a UITableView that is populated with content that can be tagged/bookmarked by a user. My app successfully sends the bookmark info to a server-side database when content is bookmarked. I'm trying to figure the most efficient way to display a bookmarked image in the respective cell if the content has already been bookmarked by the user.
For example, a user taps a cell's bookmark and the bookmark image displays a different image to verify the bookmark. The bookmark info is sent to the database. This already works
Here's where I need help...
When the user opens the app again, the UITableView is re-populated with data. If the cell contains content that has been bookmarked, I need to display the bookmarked image in the cell. Right now, I have a database query in ViewDidLoad that pulls the user's bookmarks. The only implementation I can think of is searching through the query data in cellForRowAtIndexPath. However, I know this is going to affect my scrolling performance. Is there a better way to do this?
If you don't have millions of bookmarks, then checking the bookmark flag on each cellForRowAtIndexPath should not impact the performance much.
In my experience table view scrolling is very very efficient, and there is still plenty of processor time to do other things. Doing a simple check for a value at an index shouldn't affect it much. Perhaps the best way to approach it, would be to parse your query result and create a dedicated NSArray with ONLY the YES/NO flag at each respective index, that you can check during cellForRowAtIndexPath to make a decision whether you show the bookmarked indicator or not.
If you really need to gain as much speed as possible, you could create a C array viewDidLoad with 0/1 values at each specific index and access it array[index]. This removes ANY additional overhead that could be there in NSArray. But again - my experience shows that for these kinds of uses, the overhead is minimal.

Alternate text for empty UITableView?

I am using a UITableView to display some data which the user can filter. If a certain (perfectly "legal") combination is selected, all data is filtered out (hidden). I would like to display some text stating that no results were found and to please modify your filters.
Does anything trigger when this occurs that I can hook in to?
Or will I have to manually check for an empty data set and create a custom view to display my text? (I was thinking of creating a blank cell and using that footer? Hoping for something more elegant...)
I found a similar question, but the solution is not what I am looking for: Handling empty UITableView in UITableViewController
Also, I have an Android programming background and use this exact feature frequently, I would be surprised if Apple didn't do this as well!
Put a custom view with your error text message behind the table. Then when there is no data to be displayed set table.alpha=0.0 (or table.hidden=YES), while when you have this data available set table.alpha=1.0 (or table.hidden=NO).
You can do the control on the "OK" button (or equivalent) of the filter.

Resources