0

I have copied some files from a very small (and working) project to a bigger Xcode project. In particular I have copied a xib file (with just one UIView subclass element), the UIView subclass, and ViewController. The smaller project simply draws a color background and draws circles as long as the user touches the screen.

I have adapted the code of the bigger project so that at the beginning it loads the xib file. I have added this to the AppDelegate so that it loads the new xib instead of the old one. (see edit #1 for more details)

Even if drawRect is called (I've tested adding NSLog) nothing is shown[*]. Moreover if I click on the screen of the simulated iPhone the app crashes.

int retVal = UIApplicationMain(argc, argv, nil, nil);
Program received signal EXC_BAD_ACCESS

I am not sure where the problem lies so please let me what I can post. I have Xcode 4 and I am working with iOS 5.

Thanks for your help. I hope this question is not too naive.

EDIT #1: This is my xib with a list of classes. I am trying to edit the source code for a Jabber Client that I have found here inserting my own views. I cannot post image but this is the link

https://i.stack.imgur.com/gDsNb.png

The class CircleDrawer is handling touches and drawing circles. The class MTViewController is sending a test message. The class JabberClientAppDelegate (basically unchanged from the downloaded code), connects to the server and authenticates the user. What I have changed is this method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[MTViewController alloc] initWithNibName:@"MTViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;

/*
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;*/

}

EDIT #2: I am starting from scratch. I am trying to rebuild the app but I get a crash. I have started another discussion since it is not directly relevant to this problem. EXC_BAD_ACCESS right after touchesBegan

[*]: if I simulate pressing the home button for an instant I can see the background color (then of course I don't see anything else because the simulator returns to the springboard).

21
  • I suspect you haven't connected things up in Interface Builder.
    – trojanfoe
    Nov 21, 2011 at 13:44
  • That's what I am afraid of too... could you maybe tell me how to do it? I have been looking for tutorials on this but they all refer to the "App Delegate" object in Interface Builder... which I don't have (I only have file's owner, first responder, and my custom UIView)
    – ios-lizard
    Nov 21, 2011 at 13:55
  • Well it means you need to connect the outlets from the view controller to the view items in IB and connect the delegate back to the view controllers/app delegates, as appropriate. I cannot tell you more than that, without seeing the Xib and class definitions.
    – trojanfoe
    Nov 21, 2011 at 13:57
  • Update: you have no app delegate? You'll have to add it manually then.
    – trojanfoe
    Nov 21, 2011 at 13:58
  • Do you know why there is no app delegate? In any case I have updated the questions with more info, please let me know if you need more.
    – ios-lizard
    Nov 21, 2011 at 14:12

1 Answer 1

0

Check your MainWindow.xib.

  1. Add appDelegate object below your window (in xib).
  2. Set your class property for appDelegate object to your own appdelegate class.
  3. Then your window object should be connected to appdelegate object's window property.
  4. Now in codebase create object of your viewController class and add subview to window.

Hope this steps will give you some idea about code.

I guess you must have already followed all these steps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.