is the method distance:toPoint: declared in the class header (or just declared before the method you use it in the .m file)? If the compiler haven't seen the method, it will assume a return type of (id) and probably will complain if you try to do (id) / (id)
I'm not really sure if it's declared, but if it's not declared it would give an error about "undeclared...". I'm sure that it's not declared in the class header, so if it's declared, it's in the piece of code I've written.
I'm not really sure if it's declared, but if it's not declared it would give an error about "undeclared...". I'm sure that it's not declared in the class header, so if it's declared, it's in the piece of code I've written.
The compiler does not know it will return you a double, so it wont allow you to divide.
So it has to read it before it's possible to divide them. Thank you for this answer, however when I try to rotate or scale the image (using multitouch, what the code is for) the whole application crashes.
Code:
2011-04-18 22:40:04.647 [6511:707] rotation 0.274011
2011-04-18 22:40:04.657 [6511:707] scale inf
2011-04-18 22:40:04.726 [6511:707] *** Terminating app due to uncaught exception
I'm just a rookie, so I try to teach myself some coding with the help of the internet .
I'm not really sure if it's declared, but if it's not declared it would give an error about "undeclared...". I'm sure that it's not declared in the class header, so if it's declared, it's in the piece of code I've written.
The C language compiler is a "single pass" compiler. It compiles from top to bottom. If a function/method is declared at the bottom of a file, but you try to use it above, the compiler does not know how the method function is declared.
The compiler will make an educated guess as to how it's declared (it will assume that the result is type "id", which is a universal object pointer.)
In order to fix this problem, add the declaration of the method to the .h file for your class. Add the following line to your .h file, after the { and } that contain your local variables, and after any @property directives:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
So it has to read it before it's possible to divide them. Thank you for this answer, however when I try to rotate or scale the image (using multitouch, what the code is for) the whole application crashes.
Code:
2011-04-18 22:40:04.647 [6511:707] rotation 0.274011
2011-04-18 22:40:04.657 [6511:707] scale inf
2011-04-18 22:40:04.726 [6511:707] *** Terminating app due to uncaught exception
I'm just a rookie, so I try to teach myself some coding with the help of the internet .
You'll get infinite scale if you try to divide by zero.
Change your code to something like this:
Code:
double distance1 = [self distance:currentTouch1 toPoint:currentTouch2];
double distance2 = [self distance:touch1 toPoint:touch2];
if (distance2 == 0)
{
//handle the case where distance is zero
}
else
scale =distance1 / distance2;
It's not my app, so I don't know what you want to do if distance2 is zero. I do know that you don't want to divide by zero, because that will crash.
I gather you're writing an app that changes the size of something depending on finger drags of some sort. You need logic that detects a starting distance of zero and rejects it.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
You changed everything, and now it's crashing in a new place, with a new error. It sounds like you introduced a new bug.
What does the error tell you? It tells you you are trying to index past the end of an array. Ok, what line is it crashing on? The odds are, at that line, you have code that is trying to extract an item from an array, but the array is empty.
You need to learn to debug your code yourself. If you depend on others on the forums to find all your bugs, you're going to drive yourself (and us) crazy.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I know, I'm sorry but I just want to fix this so I can scale, rotate and move à UIImageView. How can I see which line it is? I just need to fix this but everytime I get à new error..
I know, I'm sorry but I just want to fix this so I can scale, rotate and move à UIImageView. How can I see which line it is? I just need to fix this but everytime I get à new error..
Make sure you are running a debug build. When it crashes, XCode should show a source window, with an arrow on the left margin, pointing at the line of the crash. The line of the crash should also be highlighted. It will look something like this: (from XCode 4.02, but XCode 3.x will look similar)
My bet is that at the line of the crash, you'll find an expression like this:
Code:
[someArray objectAtIndex: index]
The name of the array and the index variable will be different, obviously.
The error says:
"-[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]"
NSArray objects are zero-indexed. So if you have one item in an array, that item is in index 0.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.