-3

I decided to program an iphone app to see how easy it was. I have finalized most of the coding except this part, please help:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //1
    NSString *urlString = @"http://zaphod_beeblebrox.pythonanywhere.com/";
    //2
    NSURL *url = [NSURL URLWithString:urlString];
    //3
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //4
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    //5
    [NSURLConnection sendAsynchronousRequest:request queue:queue
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                               if ([data length] > 0 && error == nil) [UIWebView]
                               else if (error != nil) NSLog(@"Error: %@", error);
                           }];
}

@end
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • 1
    What is the error, where it is located, and what did you try and what did you intend to do? – AliSoftware Oct 03 '12 at 23:47
  • 1
    What are you trying to do with [UIWebView]? as @AliSoftware said, that doesn't make any sense -- what to replace it with depends on what you were trying to do. – rdelmar Oct 04 '12 at 00:18

2 Answers2

1

the [UIWebView] statement is nonsense/meaningless and not a valid Objective-C syntax.

(I don't even understand what your tried to do there with this statement…)

AliSoftware
  • 32,623
  • 6
  • 82
  • 77
  • what would I replace it with then? the error is the bracket after the UIWebview, it says it needs an expected identifier. – user1718637 Oct 03 '12 at 23:56
  • The error is on the `]` because this is not syntaxically correct to close the bracket here. And the thing you need to insert here to make it correct totally depend on what you want your code to do. – AliSoftware Oct 04 '12 at 07:57
  • Basically you should write something that say "I want this webview to refresh" or "I want this webview to load this specific URL" but your code says "I want WebView to." Which does not mean anything. – AliSoftware Oct 04 '12 at 08:01
1

The source of your error message is that you currently have [UIWebView], which makes no sense because the square brackets designate that you're invoking a method, but you have a class name, but you don't have any method name. It's not clear what you're trying to do. See the Object Messaging section of the Objective-C Programming Language, which talks about invoking object methods (i.e. sending the object a message).

I'm guessing you're trying to load a html page in a UIWebView? You obviously need an IBOutlet for your UIWebView. (If that doesn't make sense, I'd suggest you start with Apple's tutorial Your First iOS App.)

In my example below, I'm going to assume your IBOutlet is called webview, and thus I might advise getting rid of the NSOperationQueue and NSUrlConnection and just have the UIWebView load the html for you:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *urlString = @"http://zaphod_beeblebrox.pythonanywhere.com/";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webview loadRequest:request];
}

It might be worth going through a few iPhone programming tutorials (just google it and you'll get tons of hits), too or look at the Apple App Programming Guide or check out the wonderful resources at http://developer.apple.com.

Rob
  • 415,655
  • 72
  • 787
  • 1,044