TabController Example Object creating errors - iphone

I have a 5 tab expanded version of the TabController example supplied with Xcode 4.
I need to do some maths so have created an object to manage this.
The object is inserted just to the tab view that requires it.
It compiles fine.
HOWEVER when I click on a button to update the answer on screen it errors.
label.text = [[NSString alloc] initWithFormat:#"%.2f", c];
without the above line it doesn't.
The first line the debugger cites, in main.m, is:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SolarAppDelegate class]));
What am I doing wrong?

Please check the type of value you are having in c.
Also in new xcode you need to change some settings and add Exception break point if you want to know the exact error point.
If you have not added any exception break point then it will show you to this line only

Related

"Neither element nor any descendant has keyboard focus" when running XCTestCase in a real iPhone

I'm trying to run a UI test case where there are two input fields exists. Following is my code
let usernameTextField = app.webViews.otherElements["Identity Server"].textFields["Username"]
let passwordField = app.webViews.otherElements["Identity Server"].secureTextFields["Password"]
_ = usernameTextField.waitForExistence(timeout: 8)
usernameTextField.tap()
usernameTextField.typeText("TEST") // Breakpoint line
app.typeText("\n")
passwordField.tap()
passwordField.typeText("test")
When I run the test case normally it is failing with the error given in the question title. But if I add a breakpoint to the commented line, it will run without any error.
I tried to use following code snippets after the breakpoint line, separately.
sleep(8)
_ = passwordField.waitForExistence(timeout: 8)
But non of those work. As for further information, this is a Auth process scenario where those input fields resides in a web view.
I decided to answer myself rather than closing the question. I'll tell what went wrong in my code. The main mistake I have done was continueAfterFailure set as true. Because of that, the error shown in the wrong line not the actual error throwing line.
So the solution is,
continueAfterFailure = false
and
usernameTextField.tap()
sleep(2)
usernameTextField.typeText("TEST")
There should be a small waiting time till keyboard appears in the web view before type text.
Send the \n on the end of the string you send to the username text field:
usernameTextField.typeText("TEST\n")

Xcode 5.1.1 Thread 1: signal SIGABRT

When i run my app, after a while it stops working and say thread 1: signal SIGABRT. it says it on this code:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
It says it on this line:
int retVal = UIApplicationMain(argc, argv, nil, nil);
SIGABRT means an exception was triggered. The console log will print the exact exception message, and you need to look at that (post it here).
The problem is probably in your UIApplicationMain method
To Expand on user3109992 answer a SIGABRT usually means an exception was thrown. Generally you want to enable a global exception breakpoint so that your program will be stopped on the line of code that generated the exception rather than just crashing on main so that you can gain some meaningful information as to what happened.
To set a global breakpoint use the breakpoint navigator (looks like a diamond) on your left bar (or command 7). On the lower left click the + icon and choose "Exception Breakpoint". Now your program will crash at the point the exception is thrown. However this still won't print the actual exception to the console.
To print the exception to the console when the crash occurs select the stack frame that says something like "objc exception throw", it will be at the top of the left window. If your running on simulator type: po $eax and in general the exception will be printed to the console. Note that sometimes the register where the exception is located is different if your on a device or the 64 bit simulator so you can type: "register read" and it will give you a list of registers. The one at the top holds the exception so you can type: "po " to see it. You can have the exception print automatically when your program crashes at main by setting "Log Exceptions" in the scheme (product -> scheme-> edit scheme), accessed by choosing the diagnostic tab in the edit scheme window. However if you have a breakpoint set then your breakpoint will stop the program before the debugger gets a chance. I prefer the breakpoint approach because I usually want to poke around to understand more of whats going on when the app crashed.
I'd suggest you go back and watch some of the debugging and LLDB videos from the past couple of WWDC's as it sounds like you don't have a whole lot of experience with the debugger. The beginning videos have a ton of useful information.

Finding a bug using Xcode - attempt to insert nil value

I am getting a random bug in my app, which is causing it to crash. The problem I am facing is XCode doesn't tell me where the crash is happening only the below information. Can someone tell me how I can find out where I might be able to find the problem within the code? It must be crashing at the same point as when the app does crash it always shows the below.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary
setObject:forKey:]: attempt to insert nil value (key: 0)'
* First throw call stack: (0x381e48bf 0x37d301e5 0x381e47b9 0x381e47db 0x381516bb 0x9237b 0x91121 0x8f0c5 0x8abc1 0x37b9d 0x8b68f
0x3550850f 0x381b0577 0x3813c0cf 0x3547c3fb 0x3547dc2b 0x8d005
0x3814322b 0x34495 0x32e31 0x3372d 0x30a59 0x3813e435 0x7b1df 0x7b88d
0x79e25 0x31ca650f 0x31ca5f01 0x31c8c4ed 0x31c8bd2d 0x37f12df3
0x381b8553 0x381b84f5 0x381b7343 0x3813a4dd 0x3813a3a5 0x37f11fcd
0x31cba743 0x89e8b 0x24a4) terminate called throwing an
exception(lldb)
Have you turned on exception breakpoints? Click the + at the bottom left of the Breakpoint Navigator, then select Add Exception Breakpont.
You can right click the breakpoint to edit it…
This will cause the code to stop at the point where the error occurs.
There is a solution that I usually use on my projects, setting up some special breakpoint.
To do that:
Open XCode
Goes to "View -> Navigators -> Show Breakpoint Navigators"
Now add some new breakpoints clicking the "+" button:
Add exception breakpoint
Add Symbolic breakpoint with symbol [NSException raise]
Add Symbolic breakpoint with symbol objc_exception_throw
Run again your project, application will stop on the line that is causing your problems.
error is evident enough. in any of your line, where you are setting some object for dictionary, you key is nill, which is not allowed
your problem is that you are using setObject: forKey Method to NSDictionary just make it NSMutableDictionary then try this method you can't assign value for NSDictionary like you are trying it's only for NSMutableDictionary.
i hope you will get my point what i am try to say.
Try this:
if([myDictionary objectForKey:#"string"]!= nil && [myDictionary objectForKey:#"string"]!= Nil) { }

Why am I getting a an 'instance method not found' message here?

I'm currently using the MKHorizMenu class found here and I'm trying to understand why I am getting an instance method not found message.
I'm trying to have the app programatically do the equivalent of tapping on of the items on the view controllers first load.
My code:
// Actually select the item
[self.horizMenu.itemSelectedDelegate horizMenu:self.horizMenu itemSelectedAtIndex:0];
// Tap the button (change its background image etc)
NSArray *subs = [self.horizMenu subviews];
[self.horizMenu buttonTapped:(id)[subs objectAtIndex:0]]; // guilty line
The warning:
warning: instance method '-buttonTapped:' not found (return type defaults to 'id')
In the MKHorizMenu class the method is defined as:
-(void) buttonTapped:(id) sender
When I run the code, it performs as desired - it appears as if the first button has been tapped, and the first item is selected.
Why do I get this warning? How can I call buttonTapped properly here?
You can stop the warning by adding the method declaration for buttonTapped: to the header file for the class.

1 little error in my transition coding

http://img89.imageshack.us/img89/2554/screenshot20090910at154.png http://img89.imageshack.us/img89/2554/screenshot20090910at154.png
Full Size Image
Here you can see the code for the transition but it says there is an error before the "for"
What is it that i'm missing?
I basically want to do a fade in between images.
EDIT
Here is the updated code with the adjustments. I am still getting that error.
http://img186.imageshack.us/img186/7978/screenshot20090910at102.png http://img186.imageshack.us/img186/7978/screenshot20090910at102.png
Updated Code
The *NSArray** theImages line ends with the following
[UIImage imageNamed:#"image10.jpg"], [UIImage imageNamed:#"image11.jpg"], nil]];
The line before the for should read something like:
NSArray* theImages = [NSArray arrayWithObjects:[...], // object 1
..., // more objects
[...], // object N
nil]]; // nil must be last
Updated:
The error you are getting now is not the same as the one before. You'll need to look at more of your code in order to figure out what the error is referring to.
Also, can you post some of the code directly in your question instead of posting a picture? The font SO uses is easier to read than the one in the screenshots.
I don't know what language it is, but I beleave this line should end with ]; instead of ,
Your issues seem to be simple syntactical ones.
There is one caused by these two lines (can't see above it to see where the issue is
}
{
Also, you have a new issue with the NSArray* Definition because you have
NSArray* theImages]; = .....
^^This will cause an issue after you take care of the first one