XCODE 4.5 - Expected Identifier... (UIWebView) - iPhone - objective-c

View controller h:
#interface ViewController : UIViewController
{
IBOutlet UIWebView *WebView1;
IBOutlet UIWebView *WebView2;
IBOutlet UIWebView *WebView3;
IBOutlet UIWebView *WebView4;
IBOutlet UIWebView *WebView5;
}
#end
view controller m:
#import "ViewController.h"
#interface UIViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *myURL1 = [NSURL URLWithString:[#"http:://www.youtube.com"]];
NSURLRequest *MyRequest1 = [NSURLRequest requestWithURL:myURL1];
[WebView1 loadRequest:MyRequest1];
NSURL *myURL2 = [NSURL URLWithString:[#"http:://www.gmail.com"]];
NSURLRequest *MyRequest2 = [NSURLRequest requestWithURL:myURL2];
[WebView2 loadRequest:MyRequest2];
NSURL *myURL3 = [NSURL URLWithString:[#"http:://www.soundcloud.com"]];
NSURLRequest *MyRequest3 = [NSURLRequest requestWithURL:myURL3];
[WebView3 loadRequest:MyRequest3];
NSURL *myURL4 = [NSURL URLWithString:[#"http:://www.socialblade.com"]];
NSURLRequest *MyRequest4 = [NSURLRequest requestWithURL:myURL4];
[WebView4 loadRequest:MyRequest4];
NSURL *myURL5 = [NSURL URLWithString:[#"http:://www.fullscreen.net"]];
NSURLRequest *MyRequest5 = [NSURLRequest requestWithURL:myURL5];
[WebView5 loadRequest:MyRequest5];
}
#end
Decription:
The error is on each of the links "]". What am I dong wrong?
And I can't link/connect my outlets to the UIWebView's set up in tabs.
Please help me.

It's simple. You do not need the []'s around each string. Change it's URL to the following:
SURL *myURL4 = [NSURL URLWithString:#"http:://www.socialblade.com";
NSURLRequest *MyRequest4 = [NSURLRequest requestWithURL:myURL4];
[WebView4 loadRequest:MyRequest4];
That should solve it. If not, let me know.
Edit
Also, you are declaring your properties incorrectly, which is causing your to not connect them. You should declare your webView's like this:
View controller h:
#interface ViewController : UIViewController
#property (assign) IBOutlet UIWebView *WebView1;
#property (assign) IBOutlet UIWebView *WebView2;
#property (assign) IBOutlet UIWebView *WebView3;
#property (assign) IBOutlet UIWebView *WebView4;
#property (assign) IBOutlet UIWebView *WebView5;
#end
Then you must synthesize them in your .m
view controller m:
#import "ViewController.h"
#interface UIViewController ()
#end
#implementation ViewController
#synthesize WebView1;
#synthesize WebView2;
#synthesize WebView3;
#synthesize WebView4;
#synthesize WebView5;
After they are synthesized, you can call them as you have done. :)

Related

no visible #interface for declares the selector errors

I'm getting No visible #interface for 'NSObject' declares the selector 'viewDidLoad' on
the lines:
[super viewDidLoad];
[_viewWeb loadRequest:requestObj];
[super didReceiveMemoryWarning];
UIViewControllerHUB.m
#import "UIViewControllerHUB.h"
#interface UIViewControllerHUB ()
#property (strong, nonatomic) NSMutableArray *subItems;
#end
#implementation UIViewControllerHUB
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = #"http://conecode.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
UIViewControllerHUB.h
#import <Foundation/Foundation.h>
#interface UIViewControllerHUB : NSObject
#property (strong, nonatomic) IBOutlet UIView *viewWeb;
#end
How can I fix this?
EVERYTHING ABOVE IS NOW RESOLVED.
New error below:
Now getting 'No visible #interface for 'UIView' declares the selector 'loadRequest:'
on line
[_viewWeb loadRequest:requestObj];
In your code 'No visible #interface for UIView declares the selector 'loadRequest:' on line why you are getting this error is becuase loadRequest is not the method of UIView. But in-spite of that it is the method of UIWebView. For more refer this UIWebView documentation . So just replace UIView to UIWebView and check
//Comment this
//#property (strong, nonatomic) IBOutlet UIView *viewWeb;
//Modify this
#property (strong, nonatomic) IBOutlet UIWebView *viewWeb;
Note:- As you have created outlet of UIView. So delete the same and drag-drop UIWebView and then reconnect the outlet to UIWebView
viewDidLoad is a UIViewController method. To fix it, change to inherit from that:
#import <Foundation/Foundation.h>
#interface UIViewControllerHUB : UIViewController
#property (strong, nonatomic) IBOutlet UIView *viewWeb;
#end

Mac OS X using WebView object

I can't see the webview when I launch tha app..
In the delegate that's my code
#import <Cocoa/Cocoa.h>
#include "NewsViewController.h"
#interface AppDelegate : NSObject <NSApplicationDelegate>
#property (assign) IBOutlet NSWindow *window;
#property (nonatomic,strong) IBOutlet NSSplitView *splitView;
#property (nonatomic,strong) IBOutlet NewsViewController *newsViewController;
#end
#import "AppDelegate.h"
#implementation AppDelegate
- (void)dealloc
{
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
// 1. Create the master View Controller
self.newsViewController = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
// 2. Add the view controller to the Window's content view
[self.splitView addSubview:self.newsViewController.view];
}
#end
That's my viewcontroller
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#interface NewsViewController : NSViewController{
IBOutlet WebView *web;
}
#property (assign) IBOutlet WebView *web;
#end
#import "NewsViewController.h"
#interface NewsViewController ()
#end
#implementation NewsViewController
#synthesize web;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
-(void)loadView{
NSString *urlAddress = #"http://www.google.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[web mainFrame] loadRequest:requestObj];
}
#end
if I out one label on my view in the controller everything is fine but if I put a webview I see only a grey window.
Why this?
thanks
I do believe you need to call [super loadView] in your loadView implementation.

web view did finish load labelname.hidden = yes not working?

I am very new to iOS programming and am making a simple app. the first UITabBarItem loads a page but before it loads there is a label. I am trying to make the label disappear after the web page loads but it doesn't work. I believe I need to set the web view delegate but I don't know how.
firstcontroller.h
#import <UIKit/UIKit.h>
#interface OTFFirstViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *webPage;
#property (strong, nonatomic) IBOutlet UILabel *pageLoading;
#end
firstcontroller.m
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *fullURL = #"http://asdf.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webPage loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)_webPage
{
_pageLoading.hidden = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Insert _webPage.delegate = self; before calling loadRequest:.
You should alse modify interface definition to #interface OTFFirstViewController : UIViewController <UIWebViewDelegate>.

AudioPlayer not playing on a second view controller

I have a sound playing on buttons pushed from the main view controller which works fine. On the next view controller I also want a sound to play on buttons pushed but I'm not getting any sound. I set the two .h and .m files the same. What could my problem be? Thank you for any help.
my .m file:
#import "AboutView.h"
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#interface AboutView ()
#end
#implementation AboutView
#synthesize support;
#synthesize facebook;
#synthesize kmbdev;
#synthesize back;
#synthesize player2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNi{
if (self) {
// Custom initialization
}
return self;
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: #"sound1" ofType: #"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
self.player2 = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: NULL];
player2.volume = .5;
[player2 prepareToPlay];
}
My .h file:
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#class ViewController;
#interface AboutView : UIViewController <MFMailComposeViewControllerDelegate, AVAudioPlayerDelegate>{
AVAudioPlayer *player2;
}
#property (strong, nonatomic) IBOutlet UIButton *back;
- (IBAction)back:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *support;
#property (strong, nonatomic) IBOutlet UIButton *facebook;
#property (strong, nonatomic) IBOutlet UIButton *kmbdev;
- (IBAction)email:(id)sender;
#property (strong, nonatomic) AVAudioPlayer *player2;
#end
I have [player2 play]; at my prepare for segue and IBaction as I do on the main view controller.
Add this code in ViewDidLoad method of 2nd controller:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: #"sound1" ofType: #"wav"];
if([[NSFileManager defaultManager] fileExistsAtPath:soundFilePath)
{
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
if(fileURL)
{
self.player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
self.player2.delegate = self;
self.player2.volume = 0.5f;
[self.player2. play];
}
}
else {
NSLog(#"File DoesNot Exists");
}

UIWebView reveal webpage upon launch of application?

I'm trying to launch a URL with the UIWebView upon launch of my Mac application.
I started out with this,
ViewController.h
#import <Cocoa/Cocoa.h>
#interface ViewController : UIViewController {
IBOutlet UIWebView *webView;
}
#property (nonatomic, retain) UIWebView *webView;
#end
ViewController.m
#import "ViewController.h"
- (void)viewDidLoad {
NSString *urlAddress = #"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
With that, I get two errors that I can't figure out.
(ViewController.h) #interface ViewController : UIViewController {
Error - Cannot find interface decleration 'UIViewController', superclass of 'ViewController'
(ViewController.m) - (void)viewDidLoad {
Error - Missing context for method declaration
I'm not really familiar with is and can't find what I'm doing wrong.
For OSX app, you don't have UIViewController, instead, you have NSWindowController and NSViewController, check Mac Developer Library.
You are using IOS functions instead of OSX.
Try this
In youy .h file
#import <WebKit/WebKit.h>
WebView *myWebView;
In your .m file
- (void)windowDidLoad
{
NSString *urlAddress = #"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[myWebView mainFrame] loadRequest:requestObj];
}
Don't forget to include "webkit.framework"