Table View Checkmark if Task Complete - objective-c

I'm working in Objective C. I have a UITableViewController with about 25 cells that push to a UIViewController. When the user hits back, I want to see if the user entered the correct data for the given cell. (I have a working bool , we'll call it isCellComplete for now). If isCellComplete is true, I want to add a checkmark as the accessory to the cell. I've been trying to put the test in cellForRowAtIndexPath but that method does not seem to run and refresh the cells everytime the view appears. Anyone have suggestions?

You should look into the UITableView method reloadRowsAtIndexPaths:withRowAnimation:. This is much more elegant than reloading the whole table view. And if you don't want an animation, you can specify UITableViewRowAnimationNone and it will look just like reloadData but be much more efficient.
You should do the check in tableView:cellForRowAtIndexPath: and if the check passes, set the cell's accessory to UITableViewCellAccessoryCheckmark. Then when you tell the table view to reload the appropriate row(s), it'll automatically call tableView:cellForRowAtIndexPath: on the data source and update that cell.

You could just call
[self.tableView reloadData];
in
-(void) viewWillAppear:(BOOL)animated
And that will make cellForRowAtIndexPath be called again when the view appears

Related

UITableView not drawing Cells correctly "sometimes"

When my app displays the table, sometimes, it displays ALL the content of the database. but when i try to segue to another VC an return from that VC (Lets say, I added a new entry to the Database), it displays this. if you touch below the "Missing" cells, it segue to the correct entry though...
I've already tried using:
[self.cTableView setNeedsDisplay];
[self.cTableView setNeedsLayout];
or
[self.cTableView beginUpdates];
[self.cTableView endUpdates];
or
[self.cTableView reloadData];
but still to no avail. Is there any way of refreshing the tableview graphically?
I can't post images due to reputations but the image that I'm going to post looks like the TableView gets CUT going down.
Image:
https://dl.dropboxusercontent.com/u/1336061/StackOverflow/Untitled.jpg
Are you re-using your cell correctly?
Check the cells reuse identifier. see that the cells are not being allocated every iteration (in cellForRow delegate).
If the objects that provide data to the "Data Source" of the table change, you might as well need to call:
[table reloadData];
OR
Load the new elements with their indexes (look at the UITableView headers to use the right delegate.

How to update UITableView after adding/ updating data

I am newbie for iPhone application. For storing data, I am following this tutorial.
I understand how to save data and retrieve the same.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Any idea/ suggestion how to get this done?
Any hints would be greatfull.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Edit 1
What I want is ONLY ONE SCREEN. In the link that I have provided, it is second screen.
That should work fine. But make sure you also have done a
[tableview reloadData];
after you've changed the data in your table view data source delegate.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Why you want to do this way?
UX will not be at best.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Even if you want to do, yes you need to set delegate and datasource methods.

How to call pickerView: didSelectRow: inComponent: without user interaction?

I have a 2 components, dependent pickerView. I have a preview UIImageView that changes each time the user uses the pickerView (and triggers the didSelectRow:inComponent:). This works just as I expected.
However, I want the pickerView to trigger didSelectRow: when the app launches, so that there is a Preview the moment the user sees the UIImageView. In viewDidLoad, when I try this:
[self pickerView:picker didSelectRow:row inComponent:component]; // row and component have 0 values.
next thing that happens - the pickerView shows up blank! Remove this line, and it works perfectly again. I tried this as well:
[picker selectRow: row inComponent:component animated:NO];
thinking that it will trigger didSelectRow: however it doesn't trigger it and my UIImageView remain blank.
Any advice on how to call the didSelectRow: method without the users help?
Update: by the way, the picker is inside another UIView (not the main one). In case it matters.
didSelectRow:... will only be called if a row has been selected by user interaction. If you select a row programmatically with selectRow:... then you have to add you own logic to update other components like the image view.
The principle is valid for many other delegate functions, such as e.g. tableView:didSelectRowAtIndexPath:.
Based on your comments, this what you are looking for then.
Does UIPickerView's selectRow:inComponent:animated: call pickerView:didSelectRow:inComponent:?
You have to manually call the didSelectRow method.

Value is shown in UITableView after it is scrolled

In my iPad application, I am inserting some value on a label. That value should also appear on a UITableView in another class. When I insert the value in the label and navigate to another view, there is no value appearing on the table view but when I scroll the table view up and as it comes to its original position, the value appears. How can I fix it?
Thanks and regards
PC
When you scroll the table you are eventually reloading the data as things become visible. If you call [tableView reloadData] on viewillAppear this should get the label refreshed and displaying correctly for you.
Good Luck!
Check out the reloadData method in the documentation. You will need to call this method after changing the value so the table knows to reload the cells currently being displayed. As you scroll up the cells are being redrawn, which is why you see the new value after a scroll.
Just to clarify, the reloadData method will need to be called on the UITableView object.
[myTableView reloadData];
From the documentation:
Reloads the rows and sections of the receiver.
- (void)reloadData
Discussion
Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view's delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates

When will UITableView reloadData have updated the visibleCells?

I have a UITableView instance tableView that displays data from a server.
The tableView will have to wait until the data is received, and then gets a call to it's reloadData method. All fine, works great.
Now I have a particular method that I want to perform right after the tableView finishes creating the first set of visibleCells. For this example I'll call the method performFancyActionOnVisibleCells. It seems however, that the reloadData action is asynchronous, so I can't just do
[tableView reloadData];
[self performFancyActionOnVisibleCells];
Because the visibleCells are still empty when that second line is executed, I will have to wait a bit before calling it. Which brings me to my question.
To my knowledge there is no delegate method like tableView:didFinishReloadingData. But if I'd want to call performFancyActionOnVisibleCells with the certainty that reloadData has finished updating the visibleCells property, where would that be?
Cheers,
EP.
To answer your question directly, I am not aware of any delegate callback for what you're looking for.
But, reloadData will call [tableView cellForRowAtIndexPath] on each of your visable rows so you could put a call at the bottom of that method.
I don't think that [tableView cellForRowAtIndexPath] gets called for every cell in your table but will get called by UIKit as required before the cell is made visable (for example, when scrolling).
Damien sounds right but I think that you should look at your strategy...Users may not be expecting something to popup (at a random time). I think you should display the cells first and then populate them. Use a progress indicator until the data has arrived. Then when the data arrives, draw it into the cell and thereafter you can run your fancyActionMethod. I hope this helps!