Modifying the scroll view function scrollViewDidEndScrollingAnimation - ios

I wanted to override the function scrollViewDidEndScrollingAnimation for a reference to a tableView within a class.
In other words, I have a view and a UITableView within it, I dragged a reference to the table into the view controller and want to change the scrollViewDidEndScrollingAnimation for the same, is it possible to do so?
I have looked at previous responses to similar questions and they ask suggest making the class a scrollViewDelegate and implementing the function, but I have done so and it doesn't hit the breakpoint I have within the function even if I scroll through the table in the Simulator.

This method only gets called if the setContentOffset:animated: or scrollRectToVisible:animated: methods are called by you on the scrollView, and only if the animated parameter is set to true.
Scrolling the view in the simulator will not trigger the breakpoint in your implementation, but using either of those two methods will.
UIScrollViewDelegate Protocol Reference

Related

UICollectionView didSelect not called in a specific view hierarchy

I'm hurt to an edge case I guess?
Here is my current view hierarchy of the my problematic top most view controller.
UIView-> UIScrollView-> UIView-> UIStackView-> UICollectionView
My stack view contain multiple arranged views.
What happen is that for some reason my (non scrollable) UICollectionView is not responding to its delegate didSelectRow method.
It receive touch event, I can even see shoudlHighightCell being called. But impossible to get the didSelect method called.
It's a reusable component I'm using maybe more than 10 times all across my apps, but in this specific hierarchy, it's not working.
I've tried to remove some gesture, to fiddle with delay touch of the parent UIScrollView, but it's still not working.
Any clues?
Thanks!

UITableView not loading fully inside UIScrollView

I'm creating a ViewController that will contain as a portion of it a scrollView. In that scrollView I would like to include the view of another ViewController. When I set up this ViewController inside of the ScrollView, all of that ViewController's data is pulled from the web and even it's "ViewDidLoad" method is called. However, nothing appears except for the tableViewLines and a spinner I've created to show the page is loading. Here is what it looks like (the ScrollView in question is under Commitments and Awards):
What should be loaded inside the scrollView is a tableView that looks like this:
It may be that the tableview's delegate/datasource are not set correctly. Could you check whether tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath: are called or not?
It is not a good idea to show view of one view controller in another view controller view. Apple does not recommend it. what ever you want to do, do it in the same view controller.

How can a UIView subclass get notified when it has been added as subview to another view?

I need some kind of hook or template method to override which gets called when a view is added as subview to another view, but couldn't find it in the documentation. It must be something that gets called automatically by UIKit. The reason is that my view must start some animations as soon as there is a superview, but stop animating as soon as there is no superview anymore.
I can't override -setSuperview: as Xcode is not indicating that such class exists - and I can't call super.
You want to override - (void)didMoveToSuperview.
didMoveToSuperview
Tells the view that its superview changed.
The default implementation of this method does nothing. Subclasses can override it to perform
additional actions whenever the superview changes.

How to make a callback from a UITableViewController to another UIViewController

I followed this discussion: UITableView issue when using separate delegate/dataSource, and even though I found it super informative and useful, I have a follow up question:
So I've got a similar setup where I have a UITableView within the UIView. The UIView is controlled by it's own UIViewController (let's call it MyUIViewController) and also I moved the delegate and datasource for the UITableView into a separate subclass of UITableViewController (say, MyUITableViewController).
Everything works fine with the tableView.
The question is, how do I make a callback from MyUITableViewController to the MyUIViewController? For example, if the user selects a cell under the tableView which triggers didSelectRowAtIndexPath, I need to update something on the UIView which is actually a parent of this UITableView. So I basically need to send a message to MyUITableViewController. How would I do that?
You can use a delegate pattern in this case. I have a similar answer with sample code in this SO . In your case, the parent view controller is MyUIViewController. And the child view controller is MyUITableViewController.

How can I add more than one UITableView in a UIViewController?

Here is my app.
http://www.flickr.com/photos/baozhiqiang/6943921630/
http://www.flickr.com/photos/baozhiqiang/6943921900/
You can see three buttons at the top of the main screen. When you click it, the gallery will change to next. They are not the same layout style.
I created it by making three ScrollView in a big ScrollView. Code like this:
[backgroundScrollView addSubview:innerNewsScrollView];
[backgroundScrollView addSubview:innerHotScrollView];
[backgroundScrollView addSubview:innerLinkScrollView];
And when click the button, I changed the frame of the ScrollView.
Now there is a problem, when I add more than 100 Pictures(UIButton with image) to the ScrollView, It had crashed. I want to use UITableView replace ScrollView. But how can I Control more than one UITableView in a UIViewController?
Anybody can help me!
Two possibilities:
All the table view delegate methods include the table in question as one of the paramters, so it would simply be a case of checking which table is requesting data/information
You don't have to point your table views to the view controller. Your view controller could store two objects whose only purpose is to repond to table view delegate methods
Unless the tables are trivial, I think the second option is the cleanest.
Add all of your UITableViews in the UIViewController's view, set their tag properties to something you can distinct them and also set their delegates (usually self if your UIViewController implements the UITableViewDelegate protocol). Every method in the UITableViewDelegate passes UITableView reference as an argument and with the value of the tag property you can find out which table view is processed.

Resources