My app keeps coming up with a "Semantic Error" and keeps freezing/crashing.Everything seems to be stringed together fine and it launches without problem. TextFields work fine but as soon as I click anything else it fails and forces out. Any recommendations?
h.
#interface ViewController : UIViewController {
IBOutlet UITextField *buy1;
IBOutlet UITextField *sell1;
IBOutlet UILabel *percentage1;
IBOutlet UILabel *profit1;
IBOutlet UITextField *royalty;
IBOutlet UITextField *buy2;
IBOutlet UILabel *sell2;
IBOutlet UITextField *percentage2;
IBOutlet UILabel *profit2;
}
#property (weak, nonatomic) IBOutlet UITextField *buytext1;
#property (weak, nonatomic) IBOutlet UITextField *selltext1;
#property (weak, nonatomic) IBOutlet UILabel *percentage1;
#property (weak, nonatomic) IBOutlet UILabel *profit1;
#property (weak, nonatomic) IBOutlet UITextField *royalty;
#property (weak, nonatomic) IBOutlet UITextField *buytext2;
#property (weak, nonatomic) IBOutlet UILabel *sell2;
#property (weak, nonatomic) IBOutlet UITextField *percentagetext2;
#property (weak, nonatomic) IBOutlet UILabel *profit2;
-(IBAction)Button;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)textfieldReturn:(id)sender;
#end
m.
#implementation ViewController
//This is where I keep getting the Semantic Error "Incomplete Implementation"
#synthesize buytext1;
#synthesize selltext1;
#synthesize buytext2;
#synthesize percentagetext2;
- (IBAction)backgroundTouched:(id)sender {
[buy1 resignFirstResponder];
[sell1 resignFirstResponder];
[buy2 resignFirstResponder];
[percentage2 resignFirstResponder];
}
- (IBAction)textFieldReturn:(id)sender {
[buy1 resignFirstResponder];
[sell1 resignFirstResponder];
[buy2 resignFirstResponder];
[percentage2 resignFirstResponder];
}
int VarBuy1 = 0;
int VarSell1 = 0;
int VarProfit1 =0;
int VarPercentage1 =0;
int VarRoyalty = 0;
int VarBuy2 = 0;
int VarSell2 = 0;
int VarProfit2 =0;
int VarPercentage2 =0;
-(IBAction)Button{
VarBuy1 = ([buy1.text intValue]);
VarSell1 = ([sell1.text intValue]);
VarProfit1 = (VarSell1 - (VarSell1 * (VarRoyalty / 100)) - VarBuy1);
VarPercentage1 = (VarProfit1 / VarSell1);
VarSell2 = (VarBuy2 / ((100 - VarRoyalty) / 100 - VarPercentage2));
VarProfit2 = (VarSell2 - (VarSell2 * VarRoyalty) - VarBuy2);
profit1.text = [[NSNumber numberWithInt:VarProfit1] stringValue];
percentage1.text = [[NSNumber numberWithInt:VarPercentage1] stringValue];
sell2.text = [[NSNumber numberWithInt:VarSell2] stringValue];
profit2.text = [[NSNumber numberWithInt:VarProfit2] stringValue];
}
#end
In .h
- (IBAction)textfieldReturn:(id)sender;
In .m
- (IBAction)textFieldReturn:(id)sender
Be careful about letter cases. field and Field.
And an IBAction without (id)sender doesn't sound good.
Related
This question already has answers here:
Control more than one button using tags
(3 answers)
Closed 8 years ago.
I have a bunch of labels starting from
#property (strong, nonatomic) IBOutlet UILabel *lastNumber0;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber1;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber2;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber3;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber4;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber5;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber6;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber7;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber8;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber9;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber10;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber11;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber12;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber13;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber14;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber15;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber16;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber17;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber18;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber19;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber20;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber21;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber22;
#property (strong, nonatomic) IBOutlet UILabel *lastNumber23;
And these are aimed to be passed through on an iteration basis in a for loop here;
for (int d = 0; d < [lastNumbers count]; d++) {
int value = [[lastNumbers objectAtIndex:d] intValue];
if ([red containsObject:[NSNumber numberWithInteger:value]])
{
self.lastNumber0.text = [NSString stringWithFormat:#"%i", value];
self.lastNumber0.textAlignment = NSTextAlignmentLeft;
self.lastNumber0.textColor = [UIColor redColor];
}
if ([black containsObject:[NSNumber numberWithInteger:value]])
{
self.lastNumber0.text = [NSString stringWithFormat:#"%i", value];
self.lastNumber0.textAlignment = NSTextAlignmentRight;
self.lastNumber0.textColor = [UIColor blackColor];
}
if ([green containsObject:[NSNumber numberWithInteger:value]])
{
self.lastNumber0.text = [NSString stringWithFormat:#"%i", value];
self.lastNumber0.textAlignment = NSTextAlignmentCenter;
self.lastNumber0.textColor = [UIColor greenColor];
}
}
}
Hopefully this makes sense, where self.lastNumber0.text would be replaced with a programtical self.lastNumber[d].text <-- and I know that will not work, but that's what I'm trying to achieve, I tried this
NSString *labelName = [NSString stringWithFormat:#"lastNumber%i", d];
But cannot figure out how to do self.labelName.text = blah...
Thanks for reading and if you need any more information just ask. Thanks!
ANSWER
int yInc = 310;
for (int i = 0; i < 32; i++) {
label[i] = [[UILabel alloc] initWithFrame:CGRectMake(460, yInc, 100, 10)];
label[i].font = [UIFont boldSystemFontOfSize:11];
label[i].backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
[self.view addSubview:label[i]];
yInc = yInc - 10;
}
for (int d = 0; d < 32; d++) {
int value = [[lastNumbers objectAtIndex:d] intValue];
if ([red containsObject:[NSNumber numberWithInteger:value]])
{
label[d].text = [NSString stringWithFormat:#"%i", value];
label[d].textAlignment = NSTextAlignmentLeft;
label[d].textColor = [UIColor redColor];
}
if ([black containsObject:[NSNumber numberWithInteger:value]])
{
label[d].text = [NSString stringWithFormat:#"%i", value];
label[d].textAlignment = NSTextAlignmentRight;
label[d].textColor = [UIColor blackColor];
}
if ([green containsObject:[NSNumber numberWithInteger:value]])
{
label[d].text = [NSString stringWithFormat:#"%i", value];
label[d].textAlignment = NSTextAlignmentCenter;
label[d].textColor = [UIColor greenColor];
}
}
}
Instead of making a bunch of IBOutlets to the individual labels, make a single IBOutletCollection to all of them. Now the labels are the elements of an array and you can just cycle through that array.
I am showing data in a UITableView with a thumbnail image. Initially, when the cell is clicked on, I would reload the image from the server which would take additional time, resources, and memory. Instead of doing this, I thought of passing a pointer of the thumbnail image to the view that will be on screen and display it immediately, instead of having to redownload it. However, I am running into a problem - nothing loads when I set the imageView on the new view to the old image. Here is my code:
This is in my UITableView Class:
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
NewsViewController *newsViewController = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil dictionary: dict type:d numberOfPages:1 image: cell.imageView.image];
NewsViewController.m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dictionary:(NSDictionary *)dict type:(NSInteger)type numberOfPages:(NSInteger)pages image:(UIImage *)image{
self = [super initWithNibName:#"NewsViewController" bundle:Nil];
if (self) {
newsText = [dict objectForKey:#"content"];
newsTitle = [dict objectForKey:#"title"];
newsDate = [dict objectForKey:#"pub_date"];
d = type;
numberOfPages = pages;
imageURL = [[NSMutableArray alloc] initWithCapacity:numberOfPages];
mainImage = [[UIImage alloc] init];
mainImage = image;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
labelBody.text= newsText;
titleView.text = newsTitle;
date.text = newsDate;
if (numberOfPages == 1) {
imageScrollView.contentSize = CGSizeMake(320, 303);
pageControl.numberOfPages = 1;
CustomImageView *customImageView = [[CustomImageView alloc] initWithFrame:imageScrollView.bounds];
[imageScrollView addSubview:customImageView];
customImageView.imageView.image = mainImage;
}
}
NewsViewController.h
#import <UIKit/UIKit.h>
#import "AdWhirlView.h"
#import "AdWhirlDelegateProtocol.h"
#class Reachability;
#interface NewsViewController : UIViewController<AdWhirlDelegate, UIScrollViewDelegate>{
AdWhirlView *adView;
IBOutlet UILabel *labelBody;
IBOutlet UILabel *titleView;
IBOutlet UILabel *subTitle;
IBOutlet UILabel *date;
IBOutlet UIScrollView *scrollView;
IBOutlet UIScrollView *imageScrollView;
IBOutlet UIImageView *backgroundImage;
IBOutlet UIImage *mainImage;
IBOutlet UIPageControl *pageControl;
NSInteger numberOfPages;
NSMutableArray *imageURL;
}
#property(nonatomic,retain)AdWhirlView *adView;
#property (nonatomic, retain) NSMutableArray *imageURL;
#property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
#property (nonatomic, retain) IBOutlet UIScrollView *imageScrollView;
#property (nonatomic, weak) IBOutlet UIImageView *backgroundImage;
#property (nonatomic, retain) IBOutlet UIImageView *imageView;
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
#property (nonatomic, retain) IBOutlet UIImage *mainImage;
#property (nonatomic, strong) NSString *newsText;
#property (nonatomic, strong) NSString *newsTitle;
#property (nonatomic, strong) NSString *newsDate;
#property (nonatomic, assign) NSInteger numberOfPages;
#property (nonatomic, strong) IBOutlet UILabel *titleView;
#property (nonatomic, strong) IBOutlet UILabel *labelBody;
#property (nonatomic, strong) IBOutlet UILabel *subTitle;
#property (nonatomic, strong) IBOutlet UILabel *date;
#property (nonatomic, retain) Reachability* internetReachable;
#property (nonatomic, assign) BOOL internetActive;
-(void) checkNetworkStatus:(NSNotification *)notice;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dictionary: (NSDictionary *)dict type:(NSInteger)type numberOfPages:(NSInteger) pages image:(UIImage *)image;
- (BOOL)checkInternet;
- (void)doStuff;
- (IBAction)ad;
#end
I am using mainImage as a (UIImage *) and trying to replace the image in my customImageView class with the main Image but nothing is showing up. What am I missing here?
I guess you'd like to build some sort of caching mechanism for your UIImageView. One of the easiest ways to get all of this working is by making use of the AFNetworking library.
AFNetworking extends UIImageView with some extra methods for loading images from remote sources. AFNetworking has caching build-in, no need to reinvent the wheel :)
Take a look on the following sites:
AFNetworking
UIImageView (AFNetworking)
This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I am writing an app from the Tabbed Application template in xCode.
Without any code, the app will switch tabs with no problems.
After adding code to the first view controller, I get an error when trying to switch tabs.
here is the error message:
2012-04-26 09:43:01.171 Triangle Solver[9516:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TriSecondViewController 0x68827d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key solve.'
*** First throw call stack: (0x13ce022 0x155fcd6 0x13cdee1 0x9c6022 0x937f6b 0x937edb 0x952d50 0x23a71a 0x13cfdea 0x13397f1 0x23926e 0xdf1fc 0xdf779 0xdf99b 0xfb0a9 0xfaedd 0xf94aa 0xf934f 0xfae14 0x13cfe99 0x1b14e 0x1b0e6 0x2434bd 0x13cfe99 0x1b14e 0x1b0e6 0xc1ade 0xc1fa7 0xc1b13 0x245c48 0x13cfe99 0x1b14e 0x1b0e6 0xc1ade 0xc1fa7 0xc1266 0x403c0 0x405e6 0x26dc4 0x1a634 0x12b8ef5 0x13a2195 0x1306ff2 0x13058da 0x1304d84 0x1304c9b 0x12b77d8 0x12b788a 0x18626 0x2a0d 0x2975) terminate called throwing an exception(lldb)
firstViewResponder.h:
#import
#interface TriFirstViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *triText1;
#property (weak, nonatomic) IBOutlet UITextField *triText2;
- (IBAction)calc:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *legA;
#property (weak, nonatomic) IBOutlet UILabel *legB;
#property (weak, nonatomic) IBOutlet UILabel *hypotenuse;
#property (weak, nonatomic) IBOutlet UILabel *angleA;
#property (weak, nonatomic) IBOutlet UILabel *angleB;
#property (weak, nonatomic) IBOutlet UIButton *button1;
#property (copy, nonatomic) NSString *text1;
#property (copy, nonatomic) NSString *text2;
#end
secondViewController.h:
#interface TriSecondViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *sines1;
#property (weak, nonatomic) IBOutlet UITextField *sines2;
#property (weak, nonatomic) IBOutlet UITextField *sines3;
- (IBAction)solve2:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *angleA;
#property (weak, nonatomic) IBOutlet UILabel *sideA;
#property (weak, nonatomic) IBOutlet UILabel *angleB;
#property (weak, nonatomic) IBOutlet UILabel *sideB;
#property (weak, nonatomic) IBOutlet UILabel *angleC;
#property (weak, nonatomic) IBOutlet UILabel *sideC;
#property (weak, nonatomic) IBOutlet UISegmentedControl *segControl;
- (IBAction)aassas:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *sine1;
#property (weak, nonatomic) IBOutlet UILabel *sine2;
#property (weak, nonatomic) IBOutlet UILabel *sine3;
#end
firstViewController.m:
#interface TriFirstViewController ()
#end
#implementation TriFirstViewController
#synthesize legA;
#synthesize legB;
#synthesize hypotenuse;
#synthesize angleA;
#synthesize angleB;
#synthesize button1;
#synthesize triText1;
#synthesize triText2;
#synthesize text1;
#synthesize text2;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTriText1:nil];
[self setTriText2:nil];
[self setLegA:nil];
[self setLegB:nil];
[self setHypotenuse:nil];
[self setAngleA:nil];
[self setAngleB:nil];
[self setButton1:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (IBAction)calc:(id)sender
{
double aa = 0;
double ab = 0;
double la = 0;
double lb = 0;
double h = 0;
self.text1 = self.triText1.text;
self.text2 = self.triText2.text;
aa = [self.text1 doubleValue];
lb = [self.text2 doubleValue];
ab = 90 - aa;
la = (tan((aa * (M_PI/180))) * lb);
h = (pow(la, 2) + pow(lb, 2));
h = sqrt(h);
self.legA.text = [NSString stringWithFormat: #"%.2lf", la];
self.legB.text = [NSString stringWithFormat: #"%.2lf", lb];
self.angleA.text = [NSString stringWithFormat: #"%.2lf", aa];
self.angleB.text = [NSString stringWithFormat: #"%.2lf", ab];
self.hypotenuse.text = [NSString stringWithFormat: #"%.2lf", h];
}
#end
secondViewController.m:
#interface TriSecondViewController ()
#end
#implementation TriSecondViewController
#synthesize sine1;
#synthesize sine2;
#synthesize sine3;
#synthesize angleA;
#synthesize sideA;
#synthesize angleB;
#synthesize sideB;
#synthesize angleC;
#synthesize sideC;
#synthesize segControl;
#synthesize sines1;
#synthesize sines2;
#synthesize sines3;
BOOL mode = NO;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setSines1:nil];
[self setSine2:nil];
[self setSines3:nil];
[self setAngleA:nil];
[self setAngleB:nil];
[self setAngleC:nil];
[self setSideA:nil];
[self setSideB:nil];
[self setSideC:nil];
[self setSine1:nil];
[self setSine2:nil];
[self setSine3:nil];
[self setSegControl:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (IBAction)solve2:(id)sender
{
if (mode)
{
double aa = [self.sines1.text doubleValue];
double ab = [self.sines2.text doubleValue];
double ac = 180 - aa - ab;
double sa = [self.sines3.text doubleValue];
double sb;
double sc;
//convert degrees to radians
aa = (aa * (M_PI/180));
ab = (ab * (M_PI/180));
ac = (ac * (M_PI/180));
sb = (sa/sin(aa))*sin(ab);
sc = (sa/sin(aa))*sin(ac);
self.angleA.text = [NSString stringWithFormat: #"%.2lf", aa];
self.angleB.text = [NSString stringWithFormat: #"%.2lf", ab];
self.angleC.text = [NSString stringWithFormat: #"%.2lf", ac];
self.sideA.text = [NSString stringWithFormat: #"%.2lf", sa];
self.sideB.text = [NSString stringWithFormat: #"%.2lf", sb];
self.sideC.text = [NSString stringWithFormat: #"%.2lf", sc];
}
if (!mode)
{
double aa = [self.sines1.text doubleValue];
double ab;
double ac;
double sa = [self.sines2.text doubleValue];
double sb = [self.sines3.text doubleValue];
double sc;
aa = (aa * (M_PI/180));
ab = asin(sb*(sin(aa)/sa));
ac = 180 - aa - ab;
ac = (ac * (M_PI/180));
sc = (sa/sin(aa))*sin(ac);
self.angleA.text = [NSString stringWithFormat: #"%.2lf", aa];
self.angleB.text = [NSString stringWithFormat: #"%.2lf", ab];
self.angleC.text = [NSString stringWithFormat: #"%.2lf", ac];
self.sideA.text = [NSString stringWithFormat: #"%.2lf", sa];
self.sideB.text = [NSString stringWithFormat: #"%.2lf", sb];
self.sideC.text = [NSString stringWithFormat: #"%.2lf", sc];
}
}
- (IBAction)aassas:(id)sender
{
switch (self.segControl.selectedSegmentIndex) {
case 0:
self.sine1.text = #"Angle A/n";
self.sine2.text = #"Angle B/n";
self.sine3.text = #"Side A/n";
mode = NO;
break;
case 1:
self.sine1.text = #"Angle A/n";
self.sine2.text = #"Side A/n";
self.sine3.text = #"Side B/n";
mode = YES;
break;
default:
break;
}
}
#end
The usual reason for this error is that somewhere in a xib file or storyboard you have a link from some control or view to an IBOutlet called 'solve' but you no longer have that property or variable defined in the code of the class where the link points.
I think you could get the detailed info in Xcode debugger or gdb, the call stack is very important info.
I did it and found the result that a identifier of tableviewcell is wrong.
UIViewController compliant to NSKeyValueCoding protocol, so when set a value for undeined key and you do not override
- (void)setValue:(id)value forUndefinedKey:(NSString *)key;
it will arise a NSUndefinedKeyException exception..
[self setTriText1:nil];
[self setTriText2:nil];
[self setLegA:nil];
[self setLegB:nil];
[self setHypotenuse:nil];
[self setAngleA:nil];
[self setAngleB:nil];
[self setButton1:nil];
may be here can brings that exception. why not you write it like this:
self.triText1 = nil;
self.triText2 = nil;
self.legA = nil;
as well for sencondViewContrlloer, if you use "set method" explicitly and write wrong method, similar exception will be happened..
Like most of my problems recently, i think it's a syntax problem. I know what i want to do but i don't know how to write it. I am trying to create a Jigsaw-type application. The CGPoints represent the center point of where each image should be.
I have created 40 images and put them into an array.
I want to create 40 CGPoints and put all these points in an array.
The image at images[0] has a corresponding center at cgpoints[0] - or rather this is where the image should be placed in the jigsaw.
I'm having trouble declaring/initializing the array of CGPoints though. Below is the code:
.h file
#import <UIKit/UIKit.h>
#interface DSAAssignmentViewController2 : UIViewController
#property (weak, nonatomic) NSString *passedData;
#property (weak, nonatomic) IBOutlet UILabel *lblDisplayPreviousInput;
#property (weak, nonatomic) IBOutlet UIImageView *imgOriginal;
#property (weak, nonatomic) IBOutlet UIImageView *img1;
#property (weak, nonatomic) IBOutlet UIImageView *img2;
#property (weak, nonatomic) IBOutlet UIImageView *img3;
#property (weak, nonatomic) IBOutlet UIImageView *img4;
#property (weak, nonatomic) IBOutlet UIImageView *img5;
#property (weak, nonatomic) IBOutlet UIImageView *img6;
#property (weak, nonatomic) IBOutlet UIImageView *img7;
#property (weak, nonatomic) IBOutlet UIImageView *img8;
#property (weak, nonatomic) IBOutlet UIImageView *img9;
#property (weak, nonatomic) IBOutlet UIImageView *img10;
#property (weak, nonatomic) IBOutlet UIImageView *img11;
#property (weak, nonatomic) IBOutlet UIImageView *img12;
#property (weak, nonatomic) IBOutlet UIImageView *img13;
#property (weak, nonatomic) IBOutlet UIImageView *img14;
#property (weak, nonatomic) IBOutlet UIImageView *img15;
#property (weak, nonatomic) IBOutlet UIImageView *img16;
#property (weak, nonatomic) IBOutlet UIImageView *img17;
#property (weak, nonatomic) IBOutlet UIImageView *img18;
#property (weak, nonatomic) IBOutlet UIImageView *img19;
#property (weak, nonatomic) IBOutlet UIImageView *img20;
#property (weak, nonatomic) IBOutlet UIImageView *img21;
#property (weak, nonatomic) IBOutlet UIImageView *img22;
#property (weak, nonatomic) IBOutlet UIImageView *img23;
#property (weak, nonatomic) IBOutlet UIImageView *img24;
#property (weak, nonatomic) IBOutlet UIImageView *img25;
#property (weak, nonatomic) IBOutlet UIImageView *img26;
#property (weak, nonatomic) IBOutlet UIImageView *img27;
#property (weak, nonatomic) IBOutlet UIImageView *img28;
#property (weak, nonatomic) IBOutlet UIImageView *img29;
#property (weak, nonatomic) IBOutlet UIImageView *img30;
#property (weak, nonatomic) IBOutlet UIImageView *img31;
#property (weak, nonatomic) IBOutlet UIImageView *img32;
#property (weak, nonatomic) IBOutlet UIImageView *img33;
#property (weak, nonatomic) IBOutlet UIImageView *img34;
#property (weak, nonatomic) IBOutlet UIImageView *img35;
#property (weak, nonatomic) IBOutlet UIImageView *img36;
#property (weak, nonatomic) IBOutlet UIImageView *img37;
#property (weak, nonatomic) IBOutlet UIImageView *img38;
#property (weak, nonatomic) IBOutlet UIImageView *img39;
#property (weak, nonatomic) IBOutlet UIImageView *img40;
#property (strong, nonatomic) NSArray *imageViews;
#property CGPoint *holder1;
#property CGPoint *holder2;
#property CGPoint *holder3;
#property CGPoint *holder4;
#property CGPoint *holder5;
#property CGPoint *holder6;
#property CGPoint *holder7;
#property CGPoint *holder8;
#property (strong, nonatomic) NSMutableArray *holders;
#end
.m file
#import "DSAAssignmentViewController2.h"
#interface DSAAssignmentViewController2 ()
#end
#implementation DSAAssignmentViewController2
#synthesize lblDisplayPreviousInput;
#synthesize imgOriginal;
#synthesize img1;
#synthesize img2;
#synthesize img3;
#synthesize img4;
#synthesize img5;
#synthesize img6;
#synthesize img7;
#synthesize img8;
#synthesize img9;
#synthesize img10;
#synthesize img11;
#synthesize img12;
#synthesize img13;
#synthesize img14;
#synthesize img15;
#synthesize img16;
#synthesize img17;
#synthesize img18;
#synthesize img19;
#synthesize img20;
#synthesize img21;
#synthesize img22;
#synthesize img23;
#synthesize img24;
#synthesize img25;
#synthesize img26;
#synthesize img27;
#synthesize img28;
#synthesize img29;
#synthesize img30;
#synthesize img31;
#synthesize img32;
#synthesize img33;
#synthesize img34;
#synthesize img35;
#synthesize img36;
#synthesize img37;
#synthesize img38;
#synthesize img39;
#synthesize img40;
#synthesize passedData;
#synthesize imageViews;
#synthesize holder1;
#synthesize holder2;
#synthesize holder3;
#synthesize holder4;
#synthesize holder5;
#synthesize holder6;
#synthesize holder7;
#synthesize holder8;
#synthesize holders;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// make jigsaw piece holders
//create 8 points where the jigsaw pieces (images) will be placed
CGPoint holder1 = CGPointMake(60, 644);
CGPoint holder2 = CGPointMake(140, 644);
CGPoint holder3 = CGPointMake(220, 644);
CGPoint holder4 = CGPointMake(300, 644);
CGPoint holder5 = CGPointMake(380, 644);
CGPoint holder6 = CGPointMake(460, 644);
CGPoint holder7 = CGPointMake(540, 644);
CGPoint holder8 = CGPointMake(620, 644);
// set up array of cgpoints
holders = [NSMutableArray arrayWithObjects:[NSValue valueWithCGPoint: holder1],[NSValue valueWithCGPoint: holder2], [NSValue valueWithCGPoint: holder3], [NSValue valueWithCGPoint: holder4], [NSValue valueWithCGPoint: holder5], [NSValue valueWithCGPoint: holder6], [NSValue valueWithCGPoint: holder7], [NSValue valueWithCGPoint: holder8], nil];
// set up array of images
imageViews = [NSArray arrayWithObjects:img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16, img17, img18, img19, img20, img21, img22, img23, img24, img25, img26, img27, img28, img29, img30, img31, img32, img33, img34, img35, img36, img37, img38, img39, img40, nil];
NSString *welcomeMessage = [NSString stringWithFormat:#"Welcome %#", passedData];
UIAlertView *alert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: welcomeMessage
message:#"Once you press \"Play\" the timer will start. Good luck!"
delegate:self
cancelButtonTitle:#"I want out!"
otherButtonTitles:#"Play",nil];
[alert show];
NSLog(#"x-coord: %f, y-coord: %f", holder1.x, holder1.y);
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
if ([imageViews indexOfObject:touchedView] != NSNotFound) {
// not not found means found!
[self animateFirstTouch:touchedView withLocation:location];
} else {
return;
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
[self animateReleaseTouch:touchedView withLocation:location];
}
- (void)viewDidUnload
{
[self setLblDisplayPreviousInput:nil];
[self setImgOriginal:nil];
[self setImg1:nil];
[self setImg2:nil];
[self setImg3:nil];
[self setImg4:nil];
[self setImg5:nil];
[self setImg6:nil];
[self setImg7:nil];
[self setImg8:nil];
[self setImg9:nil];
[self setImg10:nil];
[self setImg11:nil];
[self setImg12:nil];
[self setImg13:nil];
[self setImg14:nil];
[self setImg15:nil];
[self setImg16:nil];
[self setImg17:nil];
[self setImg18:nil];
[self setImg19:nil];
[self setImg20:nil];
[self setImg21:nil];
[self setImg22:nil];
[self setImg23:nil];
[self setImg24:nil];
[self setImg25:nil];
[self setImg26:nil];
[self setImg27:nil];
[self setImg28:nil];
[self setImg29:nil];
[self setImg30:nil];
[self setImg31:nil];
[self setImg32:nil];
[self setImg33:nil];
[self setImg34:nil];
[self setImg35:nil];
[self setImg36:nil];
[self setImg37:nil];
[self setImg38:nil];
[self setImg39:nil];
[self setImg40:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void) animateFirstTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.25, 1.25);
[UIView commitAnimations];
}
-(void) animateReleaseTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
I can't tell if its all a bit of a mess or not. As you can see i've started with only 8 "holders", these are the CGPoints that represent the center of where the jigsaw pieces should be placed.
borrrden is correct. You've created a whole bunch of CGPoint pointer variables by declaring them as properties and synthesizing them. But then in your -viewDidLoad method you're declaring CGPoint structs--not CGPoint pointers--all with the same name as the properties you synthesized.
You don't need the holderN properties at all, to judge from the code. In fact, you don't even need the holderN variables in the -viewDidLoad method. You could easily get away with something like this:
- ( void )viewDidLoad
{
holders = [ NSMutableArray arrayWithObjects:
[ NSValue valueWithCGPoint: CGPointMake(60, 644) ],
...,
[ NSValue valueWithCGPoint: CGPointMake(N, N) ],
nil ];
...
}
Hard-coding the point coordinates is poor design, though. Your best option is to put the coordinates in a plist, which you can load on demand and stuff into an array. This'll mean tweaking the coordinates is just a matter of editing the plist. No recompiling required.
You are getting the message in your comment because you declare variables with the same name as your properties in the beginning of viewDidLoad.
NSPoint is not an object so you have to either use C array: NSPoint points[SIZE] or use NSValue container: [NSValue valueWithCGPoint: point]
I have a UIScrollVIew. It contains a view with different controls. I added all of them to a view and then add the view to the UIScrollView. The scroll is not activated, and the content is not centered. Here is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = texto.frame;
frame.size.height = texto.contentSize.height;
texto.frame = frame;
[self configureView];
[self.scrollView addSubview:self.contentView];
self.scrollView.contentSize = self.contentView.bounds.size;
self.contentView.userInteractionEnabled= NO;
self.scrollView.userInteractionEnabled=TRUE;
}
-(void)configureView{
self.texto.text = self.newsDetail.text;
NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:self.newsDetail.image_large]];
self.imagen.image = [UIImage imageWithData:imageData];
self.fecha.text = self.newsDetail.datePublish;
self.titulo.text = self.newsDetail.title;
}
Header code:
#interface detailNewsController : UIViewController{
UIScrollView * __weak scrollView;
UIView * __weak contentView;
}
#property (nonatomic, strong) news *newsDetail;
#property ( weak, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UIView * contentView;
#property (strong, nonatomic) IBOutlet UIImageView *imagen;
#property (strong, nonatomic) IBOutlet UILabel *fecha;
#property (strong, nonatomic) IBOutlet UILabel *titulo;
#property (strong, nonatomic) IBOutlet UITextView *texto;
-(void) configureView;
I see that you link your UIScrollView with a code variable. So check in interface builder if you enabled vertical scrolling (or horizontal one if you need it)