Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 25, 2010, 03:52 PM   #1
ws47
macrumors newbie
 
Join Date: Jun 2009
SegmentedControl not working

I'm working on the extra credit of assignment 3 on Stanford's app development class. I'm trying to do the part where you use a segmented control to choose solid or dashed lines. I added an outlet for the segmented control to my view controller. When the value of the control is changed, it calls this method in the controller:
Code:
-(IBAction)segmentedControlLineTypeChanged{
	[polyView setNeedsDisplay];
}
and here is my drawRect:
Code:
//set up the path
CGContextClosePath(context);
[[UIColor blackColor]setStroke];	
[[UIColor yellowColor]setFill];
CGContextSetLineWidth(context, 2);
if (segmentedControlLineType.selectedSegmentIndex == 0) {
	//draw solid lines
        NSLog(@"solid");
}
if (segmentedControlLineType.selectedSegmentIndex == 1) {
	//draw dashed lines
	float lengths[2] = {10, 10};
	CGContextSetLineDash(context, 0, lengths, 1);
        NSLog(@"dashed");
}
CGContextDrawPath(context, kCGPathFillStroke);
For some reason, it always draws solid lines and never dashed ones. The code for dashed lines is never run because "dashed" never shows up in the console. Any ideas?
ws47 is offline   0 Reply With Quote
Old Jul 25, 2010, 04:19 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Suppose segmentedControlLineType is nil. What would happen? How would that be possible?

Learn to use the debugger to set a breakpoint. Set the breakpoint on your drawRect method. Inspect the relevant variables. Trust me, learning how to do these things will be of incalculable benefit.

You cannot avoid debugging. You can, however, avoid learning how to use the best tools for debugging. It's better to learn how to use the debugger on simple programs, rather than complex ones.
chown33 is offline   0 Reply With Quote
Old Jul 26, 2010, 02:29 AM   #3
DennisVar
macrumors newbie
 
Join Date: Jun 2010
Quote:
Originally Posted by ws47 View Post
I'm working on the extra credit of assignment 3 on Stanford's app development class. I'm trying to do the part where you use a segmented control to choose solid or dashed lines. I added an outlet for the segmented control to my view controller. When the value of the control is changed, it calls this method in the controller:
Code:
-(IBAction)segmentedControlLineTypeChanged{
	[polyView setNeedsDisplay];
}
and here is my drawRect:
Code:
//set up the path
CGContextClosePath(context);
[[UIColor blackColor]setStroke];	
[[UIColor yellowColor]setFill];
CGContextSetLineWidth(context, 2);
if (segmentedControlLineType.selectedSegmentIndex == 0) {
	//draw solid lines
        NSLog(@"solid");
}
if (segmentedControlLineType.selectedSegmentIndex == 1) {
	//draw dashed lines
	float lengths[2] = {10, 10};
	CGContextSetLineDash(context, 0, lengths, 1);
        NSLog(@"dashed");
}
CGContextDrawPath(context, kCGPathFillStroke);
For some reason, it always draws solid lines and never dashed ones. The code for dashed lines is never run because "dashed" never shows up in the console. Any ideas?
I'm sure you already looked at this, but have you actually hooked up the segmentedControlLineType via an IBOutlet in Interface Builder? as chown33 points out, segmentedControlLineType may be nil here...
__________________
I make apps for iOS and Mac.
2011 Macbook Air, 2009 Mac Mini, iPhone 4, iPhone 5
DennisVar is offline   0 Reply With Quote
Old Jul 26, 2010, 09:20 AM   #4
ws47
Thread Starter
macrumors newbie
 
Join Date: Jun 2009
All my connections are done correctly. I used to debugger and saw the segmentedControlLineType is nil (it has a value of 0x0), which is what is causing my problem. I still can't figure out why it is nil though.
ws47 is offline   0 Reply With Quote
Old Jul 26, 2010, 09:25 AM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Is it connected to a property with attribute retain? If not then that's probably the problem...
robbieduncan is offline   0 Reply With Quote
Old Jul 26, 2010, 12:26 PM   #6
ws47
Thread Starter
macrumors newbie
 
Join Date: Jun 2009
Quote:
Originally Posted by robbieduncan View Post
Is it connected to a property with attribute retain? If not then that's probably the problem...
It is now, but that doesn't solve the problem.
ws47 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
WiFi Sync Not Working iOS7, Working iOS6 kramden88 iOS 7 0 Jan 2, 2014 02:45 PM
iPhone: iPhone 5 / iPad 3 with Airport Extreme and WPA2 not working, WPA working ManuCH iOS 6 7 Aug 13, 2013 08:20 PM
Backspace & 'V' not working on keyboard passwords not working, Please help paintitblack Mac Peripherals 8 Jul 12, 2013 05:35 AM
General: The List of iOS 6 Compatible Jailbreak Tweaks (Working/Non Working) HeyGreggie Jailbreaks and iOS Hacks 363 Feb 26, 2013 06:43 PM
Why background process stops working when other programs are working? kenreaves iPhone Tips, Help and Troubleshooting 4 Aug 3, 2012 12:06 PM

Forum Jump

All times are GMT -5. The time now is 09:26 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC