Note that there are some explanatory texts on larger screens.

plurals
  1. POcan anyone work out why my app is crashing when i move the slider
    primarykey
    data
    text
    <p>When i move the slider it crashes the app. i know it is something to do with the argument i am passing to maxProcess method. it works fine if i take this out. but i need it to update the newEvent objects instance variable. Any ideas. This is what i have been told in another forum but i don;t know how to do this</p> <p>"this code declares a new object newEvent that is never allocated and initialized. If you want this method to know about the newEvent instance variable in you MainViewController class you need to pass a reference to it into your FlipSideViewController class and use that reference in your maxProcess: method."</p> <p>Flipsideviewcontroller.m</p> <pre><code>#import "FlipsideViewController.h" @implementation FlipsideViewController @synthesize delegate, sliderLabel; - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; } -(IBAction) sliderChanged:(id) sender { UISlider *slider = (UISlider *) sender; int progressAsInt = (int)(slider.value +0.5f); [self maxProcess: progressAsInt]; NSString *newText = [[NSString alloc] initWithFormat:@"Max: %d", progressAsInt]; sliderLabel.text = newText; [newText release]; } -(void) maxProcess: (int) n { Headcount *newEvent; newEvent.maxCapacity = n; // This is the area that appears to be the problem, makes i phone simulator crash } /* -(void) maxProcess: (int) n { Headcount *newEvent; newEvent.maxCapacity = n; // This is the area that appears to be the problem, makes i phone simulator crash }*/ - (IBAction)done:(id)sender { [self.delegate flipsideViewControllerDidFinish:self]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } </code></pre> <p>mainviewcontroller.m</p> <pre><code>#import "MainViewController.h" @implementation MainViewController @synthesize displayString, displayStringOut, display, displayOut; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { self.displayString = [NSMutableString stringWithCapacity:40]; // Initializes string self.displayStringOut = [NSMutableString stringWithCapacity:40]; [super viewDidLoad]; } - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller { [self dismissModalViewControllerAnimated:YES]; } - (IBAction)showInfo:(id)sender { FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil]; controller.delegate = self; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; [controller release]; } -(void) processDigit:(int)digit { [displayString setString:[NSString stringWithFormat: @"Total Number Inside: %i",digit]]; [display setText: displayString]; } -(void) processDigitOut:(int)digit { [displayStringOut setString:[NSString stringWithFormat: @"Total Number Exited: %i",digit]]; [displayOut setText: displayStringOut]; } -(IBAction) clickClear: (id) sender { newEvent.totalIn = 0; newEvent.totalOut = 0; [displayString setString:[NSString stringWithFormat: @"Total Number Inside: %i",newEvent.totalIn]]; [display setText: displayString]; [displayStringOut setString:[NSString stringWithFormat: @"Total Number Exited: %i",newEvent.totalOut]]; [displayOut setText: displayStringOut]; } -(IBAction) clickIn: (id) sender { int x = newEvent.maxCapacity; if (newEvent.totalIn &lt; x) { int digit = [sender tag]; [self calculateTotalIn: digit]; } else { [displayString setString:[NSString stringWithFormat: @"Total Capacity Reached: %i",newEvent.totalIn]]; [display setText: displayString]; } } -(IBAction) clickOut: (id) sender { if (newEvent.totalIn &lt;= 0 ) { [displayString setString:[NSString stringWithFormat: @"There is no one left, you may as well go home"]]; [display setText: displayString]; } else { int digit = [sender tag]; [self calculateTotalIn: digit]; [self calculateTotalOut: digit]; } } -(void) calculateTotalIn: (int) n { int x = newEvent.maxCapacity; newEvent.totalIn = newEvent.totalIn + n; if (newEvent.totalIn == x) { [displayString setString:[NSString stringWithFormat: @"Total Capacity Reached: %i",newEvent.totalIn]]; [display setText: displayString]; } else { [self processDigit: newEvent.totalIn]; } } -(void) calculateTotalOut:(int)n { if (newEvent.totalIn &gt;= 0) { newEvent.totalOut = newEvent.totalOut - n; [self processDigitOut:newEvent.totalOut]; } else { [displayString setString:[NSString stringWithFormat: @"There is no one left, you may as well go home"]]; [display setText: displayString]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload