Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-08-2009, 06:36 PM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 27
iPhoneDeveloper is on a distinguished road
Cool selectedsegmentIndex issue in UISegmentedControl

Hi,

I have a UISegmentedControl and i need to perform some opertaion based on the selected segment by the user.I am capturing index using:
int selectedIndex=[sender selectedSegmentIndex];

but this index is not coming correctly.If initially i have "0" index as selected and if i click on same segment again it gives me index as "1" which is wrong.

I am really struck here...Please help!!!!!!!

Thanks.
iPhoneDeveloper is offline   Reply With Quote
Old 05-08-2009, 10:38 PM   #2 (permalink)
Reena
 
Join Date: Apr 2009
Posts: 31
reena is on a distinguished road
Default

Quote:
Originally Posted by iPhoneDeveloper View Post
Hi,

I have a UISegmentedControl and i need to perform some opertaion based on the selected segment by the user.I am capturing index using:
int selectedIndex=[sender selectedSegmentIndex];

but this index is not coming correctly.If initially i have "0" index as selected and if i click on same segment again it gives me index as "1" which is wrong.

I am really struck here...Please help!!!!!!!

Thanks.

set this
[ObjSegmentedControl setMomentary:YES];
reena is offline   Reply With Quote
Old 10-21-2009, 07:53 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 1
adriancoul is on a distinguished road
Default OK, but what if we don't want a bool value.

I understand how this could be valuable if we wanted 1 or 0, yes or no...
But what if I want to grab the index of the array, and use that in a calculation with integers.. 0, 1, 2, 3, 4, 5 for example..

any help? should I be using another form of segmented control?

Adrian
adriancoul is offline   Reply With Quote
Old 10-21-2009, 08:01 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: Toronto, ON
Posts: 111
CanadaDev is on a distinguished road
Default

Code:
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.momentary = NO; // NO is the default value. Set to "NO" if you'd like the selected segment to stay selected until another one is selected
segmentedControl.selectedSegmentIndex = 0; // this handles which segment is selected first
Code:
- (void)segmentAction:(id)sender {
	// The segmented control was clicked, handle it here 
	segmentedControl = (UISegmentedControl *)sender;
	NSLog(@"Segment clicked: %d", segmentedControl.selectedSegmentIndex);
}
CanadaDev is offline   Reply With Quote
Reply

Bookmarks

Tags
selectedsegmentindex, uisegmentedcontrol

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 318
6 members and 312 guests
givensur, guusleijsten, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0