iphone Table View Issue - iphone

i have two arrays one for search bar and other for contact array. and first one display as tableview. the problem is that when i select two contacts from contact list and then i try to go on my search bar the selected contacts gone as shown in figure 2.
i try to reload table data but it didnot work. please help me... tha nks in advance.

You have a issue with the cells my best guess you have to do something like this before acctually drawing the cell in cellForRowAtIndexPath:
cell.clearsContextBeforeDrawing = YES;
If that doesn't work it's probably a problem with the indexPath, could you provide some more information related to the code?

If your cells are being released or redrawn at any point, they won't remember they were selected unless you are storing this data somewhere. The cells will be redrawn to their original state OR potentially reused if you are enabling this. I would track your selected cells alongside your contacts array (maybe an NSDictionary?).

Related

Custom Cell with Button Memory Problems

I have a custom cell that contains a button in a table view. The button is used as a toggle to essentially serve as a "checkbox" for a user to check off certain items in the list. I was having the issue in which the buttons in these table cells seemed to be sharing memory locations as a result of the dequeuereusablecellwithidentifier. When a button was pressed, it would also press every 4th or 5th button in the list.
I changed it to create my cells in a method into an array which then populates the tableview. This works fine for what I am trying to achieve, however it poses an issue when dealing with large row counts. The tableview itself runs quickly, but the initial load can be 3-4 seconds at times when there are over 100 rows. The iteration to create the cells and then populate it to the tableview is quite cumbersome.
What other methods can you populate a tableview with custom cells and buttons while still retaining unique memory for the buttons within?
Any help would be appreciated!
Thanks :)
You definitely don't want to change the way the creation of cells work- dequeuereusablecellwithidentifier is a very good thing for the reasons your seeing.
The solution is that you should store the result of the button/checkbox press in a separate data structure, like an NSArray full of NSNumber. As your table scrolls and cells are reused, you reset the state of the checkbox to whatever state it should be based on your NSArray.
Good luck!

How to reload a UITableView for more data?

I have UITableView, which I fill from a JSON Query.
I fill it with Private Messages and it works.
The JSON Query has the properties of "site" in which I get for every site 20 PMs. So at the beginning I got Site=0 and got 20PMS which are loaded.
Now I wanna have the features like in the Email-app (i believe I saw it there): When you scroll down and reach the end (in my app reached the 20. PM), the application should load the next 20 and so on and so on.
Any ideas how to realize?
Save the index path of your last row and implement
[UITableView reloadRowsAtIndexPaths:withRowAnimation:]
Or you can use scrollToRowAtIndexPath:atScrollPosition:animated:
scrollPosition
A constant that identifies a relative position in the receiving table view
(top, middle, bottom) for row when scrolling concludes.
See “Table View Scroll Position” a descriptions of valid constants in docs
And once you get you last scroll position just reload your table view [tableView reloadData]
But there is problem i guess once you reload the data i think after reloading(I am not sure) tableView it will take you to first row again then you can always save the lastIndexpath of that tableView and after reloadData just scrollToRowAtIndexPath:atScrollPosition:animated: or you can use scrollToNearestSelectedRowAtScrollPosition:animated:
I think you can implement feature like email app using your custom logic. What you do is keep the last row of tableview for loading more data. There should be message like "Load more..." in that last row. Whenever user touches that row, you should load more data and update tableview.
Stephen James and his colleagues at Key Options Development came across a similar problem: http://blog.keyoptions.co/tableview-with-automatic-load-more
They have built a sample app (ContinousTableview) that should be of some help to you. The source code is available at GitHub: https://github.com/stephenjames/ContinuousTableview

Handling an empty Table view

What I am trying to do is pretty simple, I just want to display some message to the user that there are no entries in this table, rather than just displaying a blank page. An ideal example is in the app store, if you search for something, but get no results, it just displays in the middle of the page "No Matches".
I've looked at a few solutions, and decided that the one i like best is here But theres a few little problems with it:
1) I can still drag around the image as if it was just a very large cell in the tableview
2) when I try to re-add the tableview to the tabelviewcontroller's view, I seem to get some kind of infinite recursion that eventually crashes
Anyone know a simpler way to do this? Or how I can resolve my current issues?
Don't remove the tableView, just add an UIView with your message (i.e. UIImageView) on top off it. It only needs to be big enough to cover the tableView. Place something like
at the appropriate place in your UITableViewController:
if (results == 0) {
[self.view addSubview:noResultsView];
}
Dan F it's very easy all you need to do is the following:
if there is no data in your source, add one object like No Data Found
Set a flag like BOOL bNoDataFound = YES
in CellForRowAtIndexPath delegate check your flag is YES fill the only cell with your text that you set before

Some cell in table view should be checkmarked?

I am making app where a list of countries to be shown. When the first time app runs the user selects the no. of countries. I stored that list in nsuser defaults. I want to checkmark those countries in the TableView when the app runs again for second time.
One more problem is when I scroll through the TableView and again come to the previous position, the checkmark does not show. Why this happens??
In -tableView:cellForRowAtIndexPath: you should set wether or not a checkmark should be shown based on your internal model (which in your case comes from NSUserDefaults). In the tableView:didSelectRowAtIndexPath:, do not simply make the checkmark visible in the cell, but store in in your internal model as well. This way when a cell is being shown again, it will show up correctly.
This happens because the table Cells are reused so when you Scroll up they are cleaned and reused by the below data and when you go up again all the thing is happened again.
Regarding Checking again on second time.
Just store the index of the row in NSUserDefault and put the condition in cellForRowAtIndexPath that when the index is matched keep it Checked.
Hope this helps..
hAPPY cODING...

How can I add to the contents of UITableView via a button?

I have a UITableView subclass which initially holds nothing, however by pressing a button I want to be able to add a string to the data and have it show up in the view. How can I do this? I have been trying to simply modify listdata, but this only seems to work once as after that the Table view does not reload, even though I can see more things are being added to list data. Am I missing something? Any help would be greatly appreciated!
See Inserting and Deleting Rows and Sections.
When you have added it to the datasource, call [yourTableViewObject reloadData];.