I'm trying to make a multiCanvas and everything seems right since xcode has not given me any errors. However, my build crashes, and I can't seem to find what the problem is. Can someone please review my code and see if there is something missing? If there is a problem how could I fix it?
I've basically been following the tutorial on the c4 website.
BUT here is my code:
//
// C4WorkSpace.m
// Mudascode
//
// Created by Mudassir Iqbal on 2013-10-06.
//`enter code here`
#import "C4Workspace.h"
#import "WorkSpaceBViewController.h"
@implementation C4WorkSpace
{
// placing the images created into the canvas
// i_button = insulin button, display = ipad icon, reset = reset button
C4Image * i_button;
C4Image * display;
C4Image * reset;
//variables used to define the location of buttons
// img_placement = location of the images, text_placement = location of the text
CGPoint img_placement;
CGPoint text_placement;
//labels to make madditional information visible and make app ui frindly
C4Label * status;
C`enter code here`4Label * condition; // status = number output, condition = high, good, low
C4Font * font_use; // font_use = font type
C4Timer * timer;// timer = timer to tell you that you forgot to take insulin
//lets start with adding an int to represent the sugar level
// CHANGE THIS RANGE.. I dunno what's the highest possible insulin range is
//figured it out!!!
int insulinNumber;
// this is the text that you input...will be parsed to int
NSString * insulinValue;
}
//creating a variable for the new subclass
WorkSpaceBViewController * workSpaceB;
C4View * currentView;
-(void)setup
{
[self inputInsulinValue];
[self imageCreate];// creates interface
[self statusUpdate];// the condition in numbers
[self conditionUpdate];// the condition of sugar
//addding the tap gesture so that the button will work
[i_button addGesture:TAP name:@"tap" action:@"tapped:"];
[self listenFor:@"tapped:" fromObject:i_button andRunMethod:@"insulinNumber"];// tap on button
[reset addGesture:TAP name:@"tap" action:@"tapped:"];
[self listenFor:@"tapped:" fromObject:reset andRunMethod:@"inputInsulinValue"];// tap on button
[self createWorkSpaces];
}
//********************************************
// updates the number of the screen
-(void) statusUpdate
{
font_use = [C4Font fontWithName:@"futura" size:35.0f]; // sets a font
NSString * ins = [NSString stringWithFormat:@"%d", insulinNumber];
status = [C4Label labelWithText:ins font: font_use]; // sets a number on screen
status.textAlignment = ALIGNTEXTCENTER; // aligns label
[status setCenter:CGPointMake(226, 428)]; // sets label in center
[status sizeToFit];
status.textColor = [UIColor colorWithRed: 0.85f // uses magenta text color
green:0.22f
blue:0.31f
alpha:1.0f];
[self.canvas addSubview:status];
// add to screen
}
//******************************----************
// updates the phrase (high, good, low) on screen
-(void) conditionUpdate
{
font_use = [C4Font fontWithName:@"futura" size:21.0f];
condition = [C4Label labelWithText:@"Calculating..." font: font_use];
condition.textAlignment = ALIGNTEXTCENTER;
[condition setCenter:CGPointMake(250, 582)];
[condition sizeToFit];
condition.textColor = [UIColor colorWithRed: 0.85f
green:0.22f
blue:0.31f
alpha:1.0f];
[self.canvas addSubview:condition];
}
// text input box
//*******************************************
-(void)inputInsulinValue
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Recorder" message:@"Please enter your glucose level:" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Enter", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
alertTextField.placeholder = @" enter glucose level";
[alert show];
}
//********************************************
// runs automatically after pressing enter... updates the numbers in variables
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
insulinValue = [[alertView textFieldAtIndex:0] text];
insulinNumber = [insulinValue intValue];
status.text = [NSString stringWithFormat:@"%d", insulinNumber];
[status sizeToFit];
[self condition];
}
//***********************************************
// sets up the images
-(void) imageCreate {
i_button = [C4Image imageNamed:@"i_button.png"];
display = [C4Image imageNamed:@"display.png"];
reset = [C4Image imageNamed:@"reset.png"];
[self.canvas addSubview: i_button];
[self.canvas addSubview: display];
[self.canvas addSubview: reset];
img_placement.x = 320;
img_placement.y = 512;
display.center = img_placement;
img_placement.x += 320;
img_placement.y = 400;
i_button.center = img_placement;
img_placement.y += 300;
reset.center = img_placement;
display.userInteractionEnabled = NO;
}
//*****************************************************
// if insulin button is pressed, a random number displays and tells you if you're good, high, or low
-(void) insulinNumber
{
//test to see if things are going smoothly
// C4Log (@"pokemon");
insulinNumber = [C4Math randomInt:400];
status.text = [NSString stringWithFormat:@"%d", insulinNumber];
[status sizeToFit];
[self condition];
timer = [C4Timer automaticTimerWithInterval:60.0f target:self method:@"update" repeats:YES];
}
//*****************************************************
// makign a conditions for the insulin levels so that message relates to the
-(void) condition {
if (insulinNumber <70)
condition.text = @"Your blood sugar level is low.";
else if (insulinNumber > 70 && insulinNumber <90)
condition.text = @"Your blood sugar level is good.";
else
condition.text = @"Your blood sugar level is high.";
[condition sizeToFit];
//write the rang and change the text to whatever
}
//*****************************************************
-(void)createWorkSpaces {
workSpaceB = [[WorkSpaceBViewController alloc] initWithNibName:@"workSpaceB" bundle:[NSBundle mainBundle]];
CGFloat offSet = self.canvas.width * 0.05f;
workSpaceB.canvas.frame = CGRectMake(offSet,
offSet,
self.canvas.width - 2 * offSet,
self.canvas.height - 44 - 2 * offSet);
[workSpaceB setup];
[self.canvas addSubview:workSpaceB.canvas];
currentView = (C4View *)self.canvas;
}
//*****************************************************
-(void)createToolBar {
CGRect toolBarFrame = CGRectMake(0, self.canvas.height - 44, self.canvas.width, 44);
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:toolBarFrame];
toolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem * flexible;
flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *b2;
b2 = [[UIBarButtonItem alloc] initWithTitle:@"WorkSpace B"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(switchToB)];
[toolBar setItems:@[flexible, b2, flexible]];
[self.canvas addSubview:toolBar];
}
//*****************************************************
-(void)switchToView:(C4View *)view transitionOptions:(UIViewAnimationOptions)options
{
if(![currentView isEqual:view]) {
[UIView transitionFromView:currentView
toView:view
duration:0.75f
options:options
completion:^(BOOL finished) {
currentView = view;
finished = YES;
}];
}
}
-(void)switchToB
{
UIViewAnimationOptions options = UIViewAnimationOptionTransitionCurlDown;
[self switchToView:(C4View*)workSpaceB.canvas transitionOptions:options];
}
//*****************************************************
@end
when i run this, it crahes and i get this error #import
#import "C4AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([C4AppDelegate class]));
}
}