dzenbot / DZNSegmentedControl

A drop-in replacement for UISegmentedControl for showing counts, to be used typically on a user profile
https://www.cocoacontrols.com/controls/dznsegmentedcontrol
MIT License
1.58k stars 178 forks source link

-[ViewController positionForBar:]: unrecognized selector sent to instance error #35

Closed Piero87 closed 9 years ago

Piero87 commented 9 years ago

Hi, i have tried to use your project in my app, in viewDidLoad i do this:

NSArray *items = @[@"Tweets", @"Following", @"Followers"];

DZNSegmentedControl *control = [[DZNSegmentedControl alloc] initWithItems:items];
control.tintColor = [UIColor blueColor];
control.delegate = self;
control.selectedSegmentIndex = 1;

but the app crash when set the delegate, and give me this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[ViewController positionForBar:]: unrecognized selector sent to instance

how i can solve?

dzenbot commented 9 years ago

Are you conforming to UIBarPositioningDelegate (or DZNSegmentedControlDelegate)? And have you implemented the -positionForBar: delegate method in your viewcontroller?

Piero87 commented 9 years ago

i have not implemented positionForBar, thanks!

dzenbot commented 9 years ago

You don't need to conform to the protocol if you don't want to change the default bar positioning.

Piero87 commented 9 years ago

how can i not conform to the protocol? in my uiviewcontroller i have also UISearchBarDelegate, and now give me this error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIBarPositionBottom not supported by UISearchBar'

in the code i have implemented this:

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)view
 {
    return UIBarPositionBottom;
   }

because i found it in the Sample project of DZNSegmentedControl

dzenbot commented 9 years ago