Update UITableView data when returning from detailView - objective-c

I update the UITableView's data source when viewDidAppear method is called on the ViewController that holds the tableview. So every time the user returns from the detailView the data is updated.
So the issue is that the UI is interrupted and the cell is selected until it is finished.
Is NSOperationQueue the best way to correct this?
Thanks for some suggestions.

Personally I would do these kind of things using either blocks or an NSOperation. The important thing is that the UI doesn't get blocked at any time if you can help it.

Related

Xcode: Reloading a portion of controller with each view

I am working on an IPhone app that, through viewDidLoad, makes a connection and pulls data into a table. I would like the controller, or at least the table, to reload every time the controller is displayed, even if someone just switched from one tab to another or closed and re-opened the app on this controller. Is there a way to do this? I can't seem to find anything, it's also kind of a hard thing to search for. I have found discussions of when to put code in viewDidLoad but not another method that is run every them the controller displays.
Thanks,
Cheryl
You want to use
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//code to reload table viewdata
}
Each time the view appears this method is called. I use this a lot in my app.
There's no way to do it by injecting code in only one place.
You can think of a workaround, like for example sending custom "reload request" notification from required parts of code:
viewDidAppear: in your view controller
applicationDidBecomeActive: (if table is presented)
tabBarController:didSelectViewController: (if switched onto controller with the table)
tabBar:didSelectItem: (same as above)
etc.
In you view controller simply observe this notification and reload data when required.
Although, whats more important: do you really need to reload data under such harsh requirements? In most cases data reload happens when
view controller's viewDidLoad: is called
it is manually initiated (button, for example)
long time passed since the last update was received
Otherwise it's just an overkill.

Slow UITabBar item loading

There is the problem in my project, this problem can bring lots of unpleasant feelings for customer.
So app is basically ground on UITabBarController and when I want to load one of UIViewController it loads too long (~ 1.5s in first launch and after switching there is seeing pause) - its very bad for user experience, as you know.
So I want to know some way to preload this section before user want to enter there (section doesn't loads first). There are few questions which can be the same with first glance but I don't want to have a solution like "spinner while loading".
If anybody knows elegant solution I'll very thankful.
Alexey
To me this sounds like you do lot of work in either your init method, the viewDidLoad or the viewWillAppear method of your UIViewController.
On the first load I don't know an answer, but you could load the other view controllers in the UITabBarController in a background thread so they are loaded when you tap them.
EDIT:
On first load you could use a very simple start screen and load the first screen also on the background thread. But then you would have to add a new view.

Table View Checkmark if Task Complete

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

Objective C Beginner: where to put code that needs to be executed once in UITableViewController

I have UITableViewController where I need to put initialization code only once to populate data source. in which method to put this code.
I tried with viewWillAppear: method, but it get executed every time view appear.
if you want to display things only once that the View has comed on screen, then yeah. go for it. Otherwise you also have ViewdidLoad or ViewWillAppear if you have to arrange things before the view begins the transition to slide in.
All of these methods will be executed every time from the tableView you tap on a row.
anyway the pattern you are trying to achieve is called singleton, you can find out about it more over here
What should my Objective-C singleton look like?
You can put it in viewDidLoad and it will be only once.
The - (void)viewDidLoad method is probably the place you want use. It gets called once the view controller has finished doing its loading code (either by loading a XIB or by calling loadView).

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!