customized uitableview with chat bubbles - iphone

I'm building a SMS like app, with chat bubbles. To do that I'm using a customized uitableview which gets data from an array and puts cells with pair indexPath on the right and with odd indexPath on the left
Everything works fine, but the only problem is that there can't be 2 cells one above the other in the same same position (left or right) and I need this as maybe a user can send 2 or more messages while the other one didn't send anything
I'm thinking in a way of doing that but nothing comes up to my mind so do you suggest a way ?

You can't assume that the two users will alternate messages back and forth, so the even/odd check will have to be thrown out.
You mention you store the messages in an array. Perhaps create another array of the same size, and when you add a message to the first array, you can add something to the second array that lets you know which user it is from. Then, when you create your cells, you can determine if it should be on the left or right using the second array, and fill the content of the bubble from the message array.

Could you just check if the message originated from the device I'm holding and put it on the left side?
If the data you are pulling from somehow identifies the user, you could easily check which user sent the message and position the cell based on that.

Related

Implement prev/next article

I'm fetching some articles from the web. I load them into array and pass them into DetailViewController, and I have 2 buttons - same like Mail, you press the ^ and you go to the next article.
Right now I do it by getting the next object of this array with objects.
But is this the most efficient way to do it?
Thanks.
Yes. (Unless you want to change your user interface, in which case you might want to consider swiping left and right instead of pressing a button.)

My data source is being changed out from under a UITableView

I have an app based on a tab bar and data retrieved from the Internet. The main tab shows a map and one of the other tabs shows incidents around the center point of the map displayed using a UITableView. If the user moves the map and then moves to the incidents page, I need to refresh the list of incidents displayed in the table. To do this I request the incidents in viewWillAppear:animated: and when that completes (asynchronously) I call the table view's reloadData method.
This works beautifully unless the user taps between the tabs quickly (e.g. display incidents, move to map, move map, move back to incidents, move back to map, etc.). At some point the incidents data source (an NSArray) is modified while the table view is trying to access it.
Here is a question that is similar:
UITableView Crashes if Data Source Is Updated During Scrolling
One of the solutions for that question describes a solution at a high level that is exactly what I want: Freeze the data source while the table is being updated. The thing I can't figure out, however, is when to unfreeze the data source. The problem is I can't find any way to be notified when the table is done being updated.
Any ideas? How do I freeze the data source while the table is being updated and then unfreeze it once the table is done being updated?
Although I'd really like to receive a notification when the table view is done accessing the data source, I found that my problem was due to modifying the data container from the work thread. The answer to this question led me to the solution:
Refreshing XML data and updating a UITableView
What I do now is fill a separate array in the worker thread and then perform a selector on the main thread to swap the updated data into the data container used by the table view.
The problem is I can't find any way to
be notified when the table is done
being updated.
I think you can assume that the data is done being loaded by checking in tableView:cellForRowAtIndexPath: to see if the last row has been loaded.
I haven't tested it, just making an assumption based on the API

Prompting user for multiple selections in an iphone app

I'm currently looking for a way to provide the user with being able to select multiple items from a collection of values.
I know this is done in the mail app whereby you can go into the edit mode of a folder and select multiple items by clicking on the circle on the left hand side.
What I'm unsure about is how this is achievable. Is anyone familiar with how to reproduce such functionality?
Thanks,
Matt Delves
The easiest way is this:
Provide a UITableView with all values the user can select.
Keep a mutable array with one object (e.g. an NSNumber) per table row to store each row's selection state.
In tableView:didSelectRowAtIndexPath:, toggle the selection state in your array for the tapped row and set the tapped cell's accessory type to checkmark or none, depending on the selection state.

How to save reordered rows only on pressing the Done button?

if i reorder rows on my table view, is it possible to save the result only if the user pressed the "Done" Button?
(Reorder is working great, but i only want to commit the final result of the positions if the user pressed the Done Button, and not every time a row is moved.)
Is there something like editingStyle == UITableViewCellEditingCellMove in commitEditingStyle?
Or is this only possible in the moveRowAtIndexPath action?
Thanks for help!
You will need to create some "editing" version of your internal data structure that you commit when the user finished editing. UITableView does not keep track of where the cells are; it relies on you to do that. It just tells you when the user asks to move things. If you don't really want to move them at that point, then you'll need to keep track of where they really are versus the current order in the TableView.
Remember, UITableViews are intentionally dumb. They don't keep track of data. They just draw things. You keep track of data (as the data source), and tell them what to draw when they ask.
I generally recommend that developers separate their actual data into a separate model class, and have the UITableView maintain a separate NSMutableArray based on that model class. In that case, during editing, you would update the UITableView's array, and when finished editing, it would send that array to the model to update the "real" data.

UITableView form

I am having very annoying issue. I have one form page with 5 custom cells. Each of them has one text field. On the bottom I have one button. In an onclick button function I am gathering values from each of the 5 described text fields.
My problem is that if my keyboard is up, I will get the values of not all but just visible text fields, the ones I don't see are null.
How to override this?
Thx,
Mladen
Separate data you have from your interface, that is store your textfield values in some other place right after you finish input. And access your data there.
UI elements are not intended to store data, but just to display it and allow input - as you can see in your case if you do not see a particular element you cannot be sure that it actually exists.
This might solve your problem..
1. Register your viewcontroller for KeboardNotifications
2.When keyboard will appear resize the view so that all fields will be visible.
3. When keboard will disappear just resize it back and continue..