Question

I want to know generally when the methods including the key words stated in the topic were called.

For example:

– tableView:willSelectRowAtIndexPath:
– tableView:didSelectRowAtIndexPath:
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex

When will the willSelectRow method called? What does the method mean by including the key words "will" "did" and "should"

Similarly, there are viewDidAppear and viewWillAppear. It's obvious when the viewDidAppear method called. But the viewWillAppear one is quite beyond me.

Hope that someone could help;)

Was it helpful?

Solution 2

willSelectRow: Tells the delegate that a specified row is about to be selected.

didSelectRow: Tells the delegate that the specified row is now selected.

should: Returns whether the table view should allow selection of the specified row.

It works the same way with viewDidAppear and viewWillAppear.

viewDidAppear: the view has already appeared.

viewWillAppear: the view is about to appear.

You can learn more in the apple documentation.

I hope that helped !

OTHER TIPS

Will:

Used to signify that something will happen (about to happen). Kind of like 'I will go to the store'.

Did:

Used to signify that something did happen (has happened). Kind of like 'I did go to the store'.

Should:

Almost always used as a delegate method that returns a BOOL. For example,

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex    

The table view is asking you if you would like to allow the row at the index specified to be selected at this point in time. Like you asking someone, 'Should I go to the store?'

viewWillAppear

There's really nothing special about this - it's just the system telling your view controller, "hey, your view is about to show onscreen, you better get ready!"

Imagine writing an app holding recipes, sponsored by the National Board for Healthy Eating.

Your sponsors have provided you with 10 recipes of steamed vegetables and one explaining how to make a delicious dessert of cream, marzipan and jam.

The sponsor's requirements are:

  • Recipes must be shown with metric/imperial units depending on the user's preferences.
  • Rumours have it that some people are not naturally excited by steamed vegetable recipes, so every 3 page views of a recipe, an animation of a cute rabbit eating a carrot must be shown at the bottom of the screen to make the app more popular.
  • When the user has viewed 5 recipes of steamed vegetables, they are entitled to see the dessert recipe. Once.

To meet these requirements, you can use the methods/notifications in this way:

On viewWillAppear, calculate the weights and volumes in either metric or imperial units and put the correct text in the various labels and text fields on the recipe page. This guarantees that the texts already are updated when shown to the user. If you do it in viewDidAppear, there will be a brief visible flash when the text is updated.

On viewDidAppear, you know that the recipe is correctly set up and visible to the user on the screen. This means that you can start the animation of the rabbit if the conditions are met. If you started the animation in viewWillAppear, it will start too early.

Lastly, if the sneaky user tries to click on the dessert recipe, you will receive the tableView:shouldSelectRow: message. Check if the conditions are met (if they have already viewed 5 steamed vegetables recipes) and if they are, return YES. Otherwise return NO, and the row selection will be cancelled by the system (and the dessert recipe not instantiated and shown).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top