Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Chelsea C.
Full Stack JavaScript Techdegree Student 3,392 Pointscreating a segment programatically
Hi guys, I'm a beginner in Objective-C & xCode, yet learning a lot of thing. I was hoping someone could help me with this, though. I'm trying to create another segment programmatically and so far so good! I've got four segments created...sized and positioned. Now, I want another segment inserted just before the designated one.
I've read the IOS Developer Library on how to do this and got this code:
- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated
I'm stuck though on what to do from here. Typing the name of my title for that segment...the number of segments..How should this look?
Thanks
3 Answers
Alex Hedley
16,381 PointsDepending how you set yours up
UISegmentControl *control = [[UISegmentedControl alloc];
[control insertSegmentWithTitle: @”Hide” atIndex: 0 animated: NO];
You see that was the method that tells you the paramters you need to pass, so you call the method and put in your values like @"TITLE", 1, NO
Alex Hedley
16,381 PointsIt's the title you want to give the segment then the position you want it, it has to be 0-the number of segments you currently have and it'll go before that number so if you say 0 it'll go first in the group
Chelsea C.
Full Stack JavaScript Techdegree Student 3,392 PointsThanks for your response, Alex Hedley , but how does the code look? Something like this: (void)insertSegmentWithTitle:(NSString *)title: 0; ?
Alex Hedley
16,381 Pointsthat's the method you are calling, you don't need the (void) or (NSString) I added how you would type it above
Chelsea C.
Full Stack JavaScript Techdegree Student 3,392 PointsChelsea C.
Full Stack JavaScript Techdegree Student 3,392 PointsThanks, Alex Hedley! That helps!