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-19-2010, 03:52 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 33
smithms is on a distinguished road
Default UISegmentedControl detail view controller

I have a tableview with detailview which loads data from a plist. On the detail view I have added a UISegmentedControl into the navigationItem.rightBarButtonItem with up and down arrow images. I want to advance to the next detail/row (without going back to the RootViewController table view) when the the "down" arrow is clicked and go to the previous detail/row when the "up" arrow is clicked. How would I go about doing that?

Thank you.

RootViewController.m
Code:
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	if (indexPath.section==0){
			
		InfoViewController *controller = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:[NSBundle mainBundle]];
		controller.title =@"My Title";
		[self.navigationController pushViewController:controller animated:YES];
		[controller release];
		
	}		
	if (indexPath.section==1){
		
	
		DetailViewController *controller = [[DetailViewController alloc] 
                                        initWithDvdData:[dao libraryItemAtIndex:indexPath.row]
                                        nibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
		
		NSLog(@"%d", indexPath.row);
				
		//controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];
		controller.title = [NSString stringWithFormat:@"Movement #%@", [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"movementnumber"]];
		[self.navigationController pushViewController:controller animated:YES];
		[controller release];  
	
	}
	
	
	
}


DetailViewController.m
Code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
	// self.navigationItem.rightBarButtonItem = self.editButtonItem;
	
	
	// Segmented Control - Custom right bar button with a view
	UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
											[NSArray arrayWithObjects:
											 [UIImage imageNamed:@"up.png"],
											 [UIImage imageNamed:@"down.png"],
											 nil]];
	
	[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
	
	segmentedControl.frame = CGRectMake(0, 0, 70, 30);
	segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
	segmentedControl.momentary = YES;
			
	UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
	[segmentedControl release];
	
	self.navigationItem.rightBarButtonItem = segmentBarItem;
	[segmentBarItem release];

 titleLabel.text = [dvdData valueForKey:@"title"];

// etc....

Do something when the segmented control is clicked (go to the next or previous record)
Code:
- (void)segmentAction:(id)sender
{
	UISegmentedControl* segCtl = sender;
	// the segmented control was clicked, handle it here 
	
	if([segCtl selectedSegmentIndex]==0){
		NSLog(@"You clicked the up arrow - the segment clicked was %d", [segCtl selectedSegmentIndex]);
	}else {
		
		NSLog(@"You clicked the down arrow - the segment clicked was %d", [segCtl selectedSegmentIndex]);
		
	}

	
	
}
smithms is offline   Reply With Quote
Reply

Bookmarks

Tags
detailview, navigation controller, navigationbarbutton, 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: 311
9 members and 302 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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