vzm
vzm

Reputation: 2450

Issue with custom UIActionSheet

I am using an custom open-source action sheet that looks like this:

My problem is that when I import the header file to my project DoActionSheet.h the code breaks, So I add in all of the "Demo" files and the code works fine only when I use the same segmented control that is being used in the demo to pick and choose styles, for example:

DoActionSheet *vActionSheet = [[DoActionSheet alloc] init];
    vActionSheet.nAnimationType = _sgType.selectedSegmentIndex;

    if (_sgStyle.selectedSegmentIndex == 0)
        [vActionSheet setStyle1];
    else if (_sgStyle.selectedSegmentIndex == 1)
        [vActionSheet setStyle2];
    else if (_sgStyle.selectedSegmentIndex == 2)
        [vActionSheet setStyle3];

But the moment that I remove the segmented control, say I choose setStyle1 and do:

DoActionSheet *vActionSheet = [[DoActionSheet alloc] init];
        vActionSheet.nAnimationType = [vActionSheet setStyle1];

What am I doing wrong here? Is there a better way to go around this? I integrate a regular iOS UIActionSheet just fine, I just would like the look of this one.

Upvotes: 0

Views: 91

Answers (1)

Aaron
Aaron

Reputation: 7145

I'm not 100% what you're trying to do, but this code doesn't set nAnimationType to an integer to change it's animation. It's simply calling the setStyle1 method which returns void You're confusing the animation values with the methods for setting the appearance of the action sheet.

DoActionSheet *vActionSheet = [[DoActionSheet alloc] init];
vActionSheet.nAnimationType = [vActionSheet setStyle1];

You probably want something like this:

DoActionSheet *vActionSheet = [[DoActionSheet alloc] init];
vActionSheet.nAnimationType = 0;   // to use the normal animation or 1
vActionSheet.nAnimationType = 1;   // to fade it in
vActionSheet.nAnimationType = 2;   // 2 to bounce/pop it in

If you want to change the appearance of the alert view's buttons, background etc... call one of these methods on the action sheet instance:

[vActionSheet setStyle1];
[vActionSheet setStyle2];
[vActionSheet setStyle3];

Finally, the demo project doesn't produce a static library or a framework, so it looks to me like you need all the source code if you're going to use this class and its extensions in your project. It shouldn't be hard to integrate the bits you need.

All you should need to do is create a new Group in Xcode called "DoActionSheet", then drag/drop (from Finder) the 3rd Party Source and DoActionSheet folders from the demo project's folder right into the new group you just created. Then you would the header files just as they're done in the demo's ViewController.m. Use that as a guide for using the DoActionSheet class.

Upvotes: 1

Related Questions