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

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];.

Related

iOS UI - how to tell user that there are no data in table view?

This is the situation:
A user filters a database by selecting keywords from a list, then presses "search". This pushes an instance of a UITableViewController subclass onto the navigation stack.
In the viewWillAppear: method, data are fetched from Core Data and stored in an ivar, ready for the table view's data source and delegate methods.
So far so good.
The UI problem arises when there are no results.
This simple architecture means that an empty result set yields an empty table view with no explanations.
It would be good for the UI to tell the user something like "Your search gave no results, please try with fewer keywords".
My question is this:
What is the best way to provide relevant feedback to the user, without having to change the architecture too much?
I was thinking about using the table header, but what do my esteemed colleagues here think?
Using the table header is not a bad option. You can go for that. You can also try other options like showing the info in a simple label or perhaps even an alert. But personally I wouldnt recommend the alert.
U can show that in UIAlertView.
You could add / show a UILabel to your view that says "No search results" (or something like that) when the table does not contain any data.
After fetching the result from core data... just count the number of rows in the result and then before displaying Table View just check if Count>0 then only go for table view ... else just display UIAlertView... this will save u from unnecessary display of UITableView
You can put AlertView when your ivar is empty and in alert button index return to the main view from where you are entering your search. This is the best way for you without changing your architecture.

iphone Table View Issue

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?).

UITableView and UITableCellView, how does this work with core plot?

I'm very new to iPhone programming, and I'm currently following tutos to understand the whole thing. I've been able to do what I needed (retrive data from a JSON http server, parse them with YAJL and plot the data in core plot). I have done this in a "simple" view where I have added a UILayerHostingView as requested by core-plot.
I am now trying to follow this tuto: http://blogs.remobjects.com/blogs/mh/2010/01/26/p973 but I am missing the first part regarding the views...
My understanding is that I need to create a view with a UITableView first. Then add a UITableCellView to make the first cell be able to contain the graph ? Is this right ? Where does the method "(id)initWithStyle:(UITableViewCellStyle)style" come from ?
For my needs, only the first cell needs to contain a graph, I will put some other info in the other cells.
As for now, I have created a new GraphListViewController, in the corresponding view I have added a listview but I do not see any auto generated methods regading cell customisation ? Do I need to implements DataSource in this controller and manually add some customisation methods ? Do I need to add a UITagbleViewCell to this UITableViewTable within IB ?
Hope I am not getting to confusing...
Thanks a lot for your help,
Best Regards,
Luc
To start with, create a new file ...
Cocoa Touch Class -> UIViewController subclass
and click the UITableViewController subclass checkbox. This will do all the tableview work for you. You can now open the xib file and change all the properties that you want for this.
Once this is done you need to populate the cells within the table. The first thing you need to do is to tell the controller how many cells to display. For this update the numberOfRowsInSection: method to return how many you want.
The next part is where you want to create the cell and is done mainly in the cellForRowAtIndexPath and for this I'm gonna redirect you to the following good tutorial on adding custom cells.
http://iphonedevelopment.blogspot.com/2009/09/table-view-cells-in-interface-builder.html
This explains a bit of the 'magic' that happens
Hope this helps
Liam

How to implement "Load 25 More" in UITableViewController

I am working on an iphone application. Application loads plenty of records from a webservice into table view controller. I would like to load 25 records initially and remaining in 25 batch on clicking something like "Load 25 more" at the end of the table view.
Any help would be grealy appreciated.
Thanks
Just put a button connected to an Event in your table footer. When the button is clicked, append the next 25 results to your already existing array of items.
After that, just do a [self.tableView setNeedsDisplay]. I use that to let my table know I have extra data in the table. By using that, there is no need to scroll to the right line in the table, because it keeps its original position.
Also, why call the viewDidAppear method, this seems wrong to me, because (ofcourse) the view already appeared and all declerations and assignments you do there are re-done. Just put the stuff you need to be done while viewing the view AND when you are appending data in a seperate method and put call that method from your button-press event and from the viewDidAppear event.
I wrote an example project that does this which you can download from GitHub https://github.com/Abizern/PartialTable
I do almost the same in my application, getting 50 first records from webservice. As a table footer I have a view with next/previous buttons, that when pressed launch a fetching request for next/previous 50 results. After fetch request is processed I call viewWillAppear:animated: for my view controller and inside to [self.tableView reloadData], so these results show up in the same table view. Of cause I'm keeping the data each time only for presented results, but it depends on your needs.
Hope this helps
I wrote something that does exactly what you describe, an put it on github : https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
Hope it'll be useful.

When should one use UITableView reloadData ? And defect associated ;)

I have built a UITableView with custom cells which each contain 5 textfields (a bit like a grid). The cells can be edited inline (no need to go in a separate view).
I am faced with some wierd defects when it comes to using reloadData.
my table footer is dynamic (calculates a value based on the cells). Should I call reloadData everytime I update a cell ? Or is there a way for the footer only to be updated?
When I start editing my cell but leave it empty (do not write any text in the textfield), the cell does not move to edit mode if I have used reloadData. Is there any known defect when doing reloadData on empty cells?
Basically I am not really sure on the best practices to use reloadData and did not find any guide anywhere. Any advice would be very much appreciated.
Regards,
Jonathan
You should minimize reloads in tableviews, and use it only when you cannot update the table other way.
For example when deleting a row you do not need a reload, just use deleteRowsAtIndexPaths or deleteSections as needed.
Other views you can just update their properties. For example if you have a label in the footer, you just need to set its text property. You do not need a table reload.
I think you cannot edit directly some properties of the cells outside cellForRowAtIndexPath method. In cases like this you will need a table reload that will call cellForRowAtIndexPath method.