c-rack / protocolblocks

Replacing delegates in iOS with blocks
46 stars 7 forks source link

UIScrollview+DelegateBlocks not working for me. #2

Closed nlabhart closed 9 years ago

nlabhart commented 9 years ago

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?

c-rack commented 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?

nlabhart commented 9 years ago

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; }];

c-rack commented 9 years ago

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

nlabhart commented 9 years ago

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

http://glab.mobi

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.

c-rack commented 9 years ago

Do I need to set the delegate in order to use the blocks?

Yes.

c-rack commented 9 years ago

@nlabhart Has setting the delegate solved your issue?

nlabhart commented 9 years ago

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

http://glab.mobi

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.

c-rack commented 9 years ago

OK, sorry for protocolblocks not being the solution you are looking for. Would you mind to close this issue then?