Solved

Using XCode and Cocoa Touch - How do find info on debugging and implementing classes properly for iPhone?

Posted on 2010-08-23
8
905 Views
Last Modified: 2013-12-12
I'm relatively new to development in XCode and Interface Builder for iPhone.  I've developed a little with C# in .NET for work.
I'm wanting to know a systematic approach to debugging and using classes properly in development.

For example, I'm writing an app, and I'm wanting to use a class I haven't implemented before, UIWebView.  I used the apple developer documentation in XCode to learn how to use it, but I've not been able to get a page running in the UIWebView yet.  The simulation runs without warnings or errors, but nothing loads in the UIWebView.

How I should go about solving this sort of problem?  What should I read, or what debugging steps should I take to get the UIWebView, or any class implemented properly?

I could post my code, but I more concerned about the proper steps to solving this type of issue rather than just to solve this example.
0
Comment
Question by:mattasks
  • 4
  • 4
8 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33498779
You need to show the code. I attached an example that you may understand already.
Any question you have, you can simply ask here.

Here is a tutorial about UIWebView:
UIWebView Tutorial
http://www.iphonesdkarticles.com/2008/08/uiwebview-tutorial.html

It's simple and works fine. It will take you few minutes to read and implement this program.

There is a debugger in Xcode. It's not the same as in Visual Studio and it will take a while to understand it and start to use it. Command + backslash set a breakpoint. You can use NSLog and it will help you to develop. The log messages you will see in the console. Actually you need to arrange the IDE per your needs. For now, simply use the Xcode menu and Google search for everything.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
  
	CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
	UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
	[webView setBackgroundColor:[UIColor whiteColor]];
	NSString *urlAddress = @"http://www.google.com";
	NSURL *url = [NSURL URLWithString:urlAddress];
	NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
	[webView loadRequest:requestObj];
	[window addSubview:webView]; 
	[webView release];	
    [window makeKeyAndVisible];
	
	return YES;
}

Open in new window

0
 

Author Comment

by:mattasks
ID: 33498850
I'm asking about the steps to solve this type of problem.  For example, if your code above compiled fine, returned no errors or warnings, but the UIWebView wouldn't load a page (just stayed as the plain whiteColor background), what steps would you take to debug it?  Where would you put brakepoints and what would you be looking for in an inspector?
Thanks
0
 

Author Comment

by:mattasks
ID: 33498863
I've done a few applications, and have mostly used tutorials and examples to help debug.  But I'm looking for a better practice to use when I can't find examples.  What are some systematic checks that I should do when this sort of problem occurs?
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33498877
1. Use NSLog for each step.
2. Set a breakpoint new NSString *urlAddress = @"http://www.google.com"; and check the variables and function returns. In may cases you can check everything in Mac OS X application. The change is simple AppKit instead of UIKit.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 500 total points
ID: 33498885
For such mistakes you use NSLog and debugger.
Xcode contains instruments for more complicated cases: memory leak detection, profiling, etc.
0
 

Author Comment

by:mattasks
ID: 33499356
Ok, thanks for those suggestions.  I'm becoming more familiar with the debugger now.
I'm trying to use breakpoints and NSLog within viewDidLoad in the view controller, but I can't get the debugger to stop at the breakpoints.  NSLog doesn't seem to write to the console either.  (I've got NSLog working successfully in another method)

- (void)viewDidLoad:(id)sender {
      NSLog(@"inside viewDidLoad override");
      [super viewDidLoad];
}

Any ideas?
0
 

Author Closing Comment

by:mattasks
ID: 33499456
Thanks for the help.  This has helped me start using the debugger and Console.  I have more questions, but I'll start them in new questions so that I can award the points for this solution first.

Thanks,
Matt
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33500061
You are welcome
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now