Closed nlabhart closed 9 years ago
@nlabhart Thank you for your issue. I'll try to help you. Could you explain what exactly "does not work"? What is the expected result? What happens instead? Also, could you please reformat your issue so that the source code becomes more readable?
Sure. The problem is that the block is not firing (NSLog call never gets written to the console).
Here is the code that is important.
[me.scrollView useBlocksForDelegate]; [me.scrollView onDidScroll:^(UIScrollView *scrollView) { CGFloat pageWidth = me.scrollView.frame.size.width; float fractionalPage = me.scrollView.contentOffset.x / pageWidth; NSInteger page = lround(fractionalPage); NSLog(@"page number %f",page); me.pageControl.currentPage = page; }];
Have you set the delegate properly? For example:
scrollView.delegate = self;
See also: https://stackoverflow.com/questions/14095874/scrollviewdidscroll-never-called https://stackoverflow.com/questions/6842568/uiscrollviewdelegate-not-firing
Do I need to set the delegate in order to use the blocks? Guess I didn't realize that.
I am setting up the UIScrollview from within a UIView, not UIViewController. This is why I was hoping to use the Blocks setup, because the UIView cannot adhere to the UIScrollViewDelegate protocol.
Sincerely,
Noah Labhart Partner, Director - GLab, LLC noah.labhart@glab.mobi Cell: 817-988-5253
On Tue, Mar 31, 2015 at 11:08 AM, Constantin Rack notifications@github.com wrote:
Have you set the delegate properly? For example:
scrollView.delegate = self;
See also:
https://stackoverflow.com/questions/14095874/scrollviewdidscroll-never-called https://stackoverflow.com/questions/6842568/uiscrollviewdelegate-not-firing
— Reply to this email directly or view it on GitHub https://github.com/c-rack/protocolblocks/issues/2#issuecomment-88145732.
Do I need to set the delegate in order to use the blocks?
Yes.
@nlabhart Has setting the delegate solved your issue?
No it did not.
I was trying to do this from a UIView, which would not meet the delegate requirements. I thought that blocks would solve my problem, without having to reference a parent ViewController as a delegate.
However, if I have to link to a parent controller as a delegate anyway, might as well implement that method in the view controller.
Thanks for your help though!
Sincerely,
Noah Labhart Partner, Director - GLab, LLC noah.labhart@glab.mobi Cell: 817-988-5253
On Thu, Apr 2, 2015 at 4:08 PM, Constantin Rack notifications@github.com wrote:
@nlabhart https://github.com/nlabhart Has setting the delegate solved your issue?
— Reply to this email directly or view it on GitHub https://github.com/c-rack/protocolblocks/issues/2#issuecomment-89044678.
OK, sorry for protocolblocks not being the solution you are looking for. Would you mind to close this issue then?
I am using your UIScrollview+DelegateBlocks class in my project. I drug these files only into my Xcode project. I am setting the delegate block within a public class method (static, +). The scrollView was created on the Storyboard, and is linked via IBOutlet. See the bottom for the specific block code. What am I missing here?
(id) tutorials:(TutorialSet)setChoice { UINib nib = [UINib nibWithNibName:@"TutorialDialog" bundle:nil]; NSArray nibArray = [nib instantiateWithOwner:self options:nil]; TutorialsView *me = [nibArray objectAtIndex: 0];
switch (setChoice) { case TutorialSetHome: me.screens = @[ @"12Bar_Homescreen_Tuts-01.png", @"12Bar_Homescreen_Tuts-02.png", @"12Bar_Homescreen_Tuts-03.png", @"12Bar_Homescreen_Tuts-04.png", @"12Bar_Homescreen_Tuts-05.png", @"12Bar_Homescreen_Tuts-06.png" ];
}
[me addTutorialImages:me.screens forScrollView:me.scrollView];
CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; CGFloat screenWidth = screenSize.width;
me.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, me.scrollView.frame.origin.y + me.scrollView.frame.size.height + 20.0, screenWidth, 50.0)]; me.pageControl.numberOfPages = me.screens.count; me.pageControl.currentPage = 1; [me addSubview:me.pageControl];
[me.scrollView useBlocksForDelegate]; [me.scrollView onDidScroll:^(UIScrollView *scrollView) { CGFloat pageWidth = me.scrollView.frame.size.width; float fractionalPage = me.scrollView.contentOffset.x / pageWidth; NSInteger page = lround(fractionalPage); NSLog(@"page number %f",page); me.pageControl.currentPage = page; }];
return me; }