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

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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: YouTube not working on Safari? deannnnn OS X 40 Dec 5, 2013 03:25 PM
Java Applet not working on Lion jake4ever Mac OS X 10.7 Lion 19 Feb 1, 2013 09:44 AM
iPhone 4 ringer not working Causality iPhone Tips, Help and Troubleshooting 3 Oct 20, 2012 01:07 AM
Youtube not working in Safari? Hyde244 Mac Applications and Mac App Store 12 Nov 16, 2011 11:12 PM
Cydia not working day 2! almac04 Jailbreaks and iOS Hacks 18 Jun 12, 2011 01:22 AM


All times are GMT -5. The time now is 12:11 AM.

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

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