I have two error : No visible #interface for 'UIWebview' - objective-c

I have two error :No visible #interface for 'UIWebView' declares the selector 'highlightAllOccurencesOfString:'
another one:No visible #interface for 'UIWebView' declares the selector 'removeAllHighlights'
Please someone help me.
WBSecondViewController.h
#import <UIKit/UIKit.h>
#interface WBSecondViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>{
}
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property(copy) NSArray *menuItems;
#property (weak, nonatomic) IBOutlet UIToolbar *webToolBar;
- (IBAction)back:(id)sender;
- (IBAction)foward:(id)sender;
-(IBAction)searchButtonPressed:(id)sender;
-(IBAction)clearHighlights:(id)sender;
#end
WBSecondViewController.m
#import "WBSecondViewController.h"
#import "Word.h"
#import "WordController.h"
#import "AddWordController.h"
#import "WBAppDelegate.h"
#import "WBFirstViewController.h"
#import "SearchWebView.h"
#interface WBSecondViewController ()
#end
#implementation WBSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Second", #"Second");
self.tabBarItem.image = [UIImage imageNamed:#"second"];
}
return self;
}
- (void)viewDidLoad
{
UIMenuController *menu = [UIMenuController sharedMenuController];
[super viewDidLoad];
NSURL *theURL = [NSURL URLWithString:#"http://www.google.co.jp"];
[_webView loadRequest:[NSURLRequest requestWithURL:theURL]];
}
-(IBAction)searchButtonPressed:(id)sender{
[_webView highlightAllOccurencesOfString:#"cat"];
}
-(IBAction)clearHighlights:(id)sender{
[_webView removeAllHighlights];
}
SearchWebView.h
#import <Foundation/Foundation.h>
#interface SearchWebView : UIWebView
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;
#end
SearchWebView.m
#import "SearchWebView.h"
#implementation SearchWebView
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"UIWebViewSearch" ofType:#"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];
NSString *startSearch = [NSString stringWithFormat:#"uiWebview_HighlightAllOccurencesOfString('%#')",str];
[self stringByEvaluatingJavaScriptFromString:startSearch];
NSString *result = [self stringByEvaluatingJavaScriptFromString:#"uiWebview_SearchResultCount"];
return [result integerValue];
}
- (void)removeAllHighlights
{
[self stringByEvaluatingJavaScriptFromString:#"uiWebview_RemoveAllHighlights()"];
}
#end

U have subclassed uiwebview and called it SearchWebView but then when you create an instance of web view in your wbsecondviewcontroller, you use a regular web view instead of the subclass that you created and the regular web view does not have the two extra methods that you defined for that custom one. Above #interface in the wbsecondviewcontroller.h do #class SearchWebView. Then where you declare the property UiWebView, declare it as a SearchWebView instead. In the .m file of the wbsecondviewcontroller do #import "SearchWebView.h"

Related

Access variable in once from another class in Objective-C

I have Two classes in have declared string in one variable and trying access from another class. have initiated getter setter in between them still getting null value when I try to print from subclass.
CustomerCarSelection.h
#import <UIKit/UIKit.h>
#interface CustomerCarSelection : UITableViewController <UITableViewDataSource, UITableViewDataSource>
#property (strong, nonatomic) IBOutlet UITableView *carListTableView;
- (IBAction)next:(id)sender;
#property NSString *carSelectedForService;
#end
customerCarSelection.m
#import "CustomerCarSelection.h"
#import <Parse/Parse.h>
#import "carSelectCellTableViewCell.h"
#import "ServiceResultView.h"
#interface CustomerCarSelection ()
#end
#implementation CustomerCarSelection
#synthesize carListTableView;
#synthesize carSelectedForService;
- (void)viewDidLoad {
[super viewDidLoad];
ServiceResultView *service = [[ServiceResultView alloc]init];
service.pointer = self;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"cell tabbed");
PFObject *temp = [cellDetails objectAtIndex:indexPath.row];
carSelectedForService = temp.objectId;
NSLog(#"%#", carSelectedForService);
}
serviceResultView.h
#import <UIKit/UIKit.h>
#import "CustomerCarSelection.h"
#interface ServiceResultView : UIViewController
{
CustomerCarSelection *pointer;
}
#property (nonatomic, retain) CustomerCarSelection *pointer;
- (IBAction)confirm:(id)sender;
#end
serviceResultView.m
#import "ServiceResultView.h"
#import "CustomerCarSelection.h"
#interface ServiceResultView ()
#end
#implementation ServiceResultView
#synthesize pointer;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *carResult = pointer.carSelectedForService;
NSLog(#"%#", carResult);
}
Where am I making mistake. When the cell tabbed it will assign object id to the String i trying access that object from another class
CustomerCarSelection.h
#import <UIKit/UIKit.h>
#interface CustomerCarSelection : UITableViewController <UITableViewDataSource, UITableViewDataSource>
#property (strong, nonatomic) IBOutlet UITableView *carListTableView;
- (IBAction)next:(id)sender;
#end
customerCarSelection.m
#import "CustomerCarSelection.h"
#import <Parse/Parse.h>
#import "carSelectCellTableViewCell.h"
#import "ServiceResultView.h"
#interface CustomerCarSelection ()
#end
#implementation CustomerCarSelection
#synthesize carListTableView;
#synthesize carSelectedForService;
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"cell tabbed");
PFObject *temp = [cellDetails objectAtIndex:indexPath.row];
serviceResultView *obj = [serviceResultView alloc] init];
obj.carSelectedForService = temp.objectId;
NSLog(#"%#", obj.carSelectedForService);
}
serviceResultView.h
#import <UIKit/UIKit.h>
#import "CustomerCarSelection.h"
#interface ServiceResultView : UIViewController
#property NSString *carSelectedForService;
- (IBAction)confirm:(id)sender;
#end
serviceResultView.m
#import "ServiceResultView.h"
#import "CustomerCarSelection.h"
#interface ServiceResultView ()
#end
#implementation ServiceResultView
#synthesize pointer;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"%#", self.carSelectedForService);
}

Delegate not informing my View

My cpViewController has a button that modal segues to cpScanViewController. I want to have cpScanViewController inform ViewController with a string when it has completed a successful scan. After reading numerous articles online, I believe delegation is the best way to do this?
Is the delegate being set correctly?
How does the delegate inform the cpViewController?
cpScanViewController.h
#import <UIKit/UIKit.h>
#protocol ScanDelegate <NSObject>
-(void)receivedUPC:(NSString *)Scan;
#end
#interface cpScanViewController : UIViewController
#property (nonatomic, weak) id <ScanDelegate> delegate;
#property (nonatomic, retain) NSString *UPC;
-(void)checkUPC;
#end
cpScanViewController.m
#interface cpScanViewController ()
{
NSString *UPC;
}
#end
#implementation cpScanViewController
#synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)doSomeScanStuff
{
UPC = #"a string"
// even tried
[delegate receivedUPC:UPC];
}
-(void)checkUPC
{
}
#end
cpViewController.h
#import <UIKit/UIKit.h>
#import "cpScanViewController.h"
#interface cpViewController : UIViewController <ScanDelegate>
#end
cpViewController.m
#interface cpViewController ()
{
cpScanViewController *cp;
}
#end
#implementation cpViewController
- (void)viewDidLoad
{
// set delegate
cp = [[cpScanViewController alloc] init];
[cp setDelegate:self];
}
-(void)receivedUPC:(NSString *)Scan{
// Nothing happening
NSLog(#"%#", Scan);
NSLog(#"The %#", cp.UPC);
}
#end
Because you are not calling receivedUPC method from your cpScanViewController class. You need to add [_delegate receivedUPC:self], some where in order to invoke this delegat method in cpViewController class.
I was able to get it working by using the method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
cpScanViewController *vd = (cpScanViewController *)[segue destinationViewController];
vd.delegate = self;
}
Because I made the connection in storyboards I didn't realize it needed to have the method.

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.

Why I get this error? At Xcode [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
I have two error : No visible #interface for ‘UIWebview’
Why I get this error at Xcode. Error is that:No visible #interface for 'UIWebView' declares the selector 'highlightAllOccurencesOfString:' and No visible #interface for 'UIWebView' declares the selector 'removeAllHighlights'. Where are wrong?
WBSecondViewController.h
#import <UIKit/UIKit.h>
#interface WBSecondViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>{}
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property (weak, nonatomic) IBOutlet UIToolbar *webToolBar;
- (IBAction)searchButtonPressed:(id)sender;
- (IBAction)clearHighlights:(id)sender;
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;
#end
WBSecondViewController.m
#import "WBSecondViewController.h"
#interface WBSecondViewController ()
#end
#implementation WBSecondViewController
-(IBAction)searchButtonPressed:(id)sender{
NSLog(#"highlighttes");
[_webView highlightAllOccurencesOfString:#"不明"];
}
-(IBAction)clearHighlights:(id)sender{
[_webView removeAllHighlights];
}
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"UIWebViewSearch" ofType:#"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[_webView stringByEvaluatingJavaScriptFromString:jsCode];
NSString *startSearch = [NSString stringWithFormat:#"uiWebview_HighlightAllOccurencesOfString('%#')",str];
[_webView stringByEvaluatingJavaScriptFromString:startSearch];
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:#"uiWebview_SearchResultCount"];
return [result integerValue];
}
- (void)removeAllHighlights
{
[_webView stringByEvaluatingJavaScriptFromString:#"uiWebview_RemoveAllHighlights()"];
}
#end
These two lines are wrong,
[_webView highlightAllOccurencesOfString:#"不明"];
[_webView removeAllHighlights];
It should be,
[self highlightAllOccurencesOfString:#"不明"];
[self removeAllHighlights];
You are trying to call highlightAllOccurencesOfString and removeAllHighlights which are defined in WBSecondViewController's #interface but on UIWebview objects. Compiler is not able to find it in UIWebView class #interface and hence the error message as No visible #interface for 'UIWebView' declares the selector ...
highlightAllOccurencesOfString and removeAllHighlights are method defined in your WBSecondViewController, while you are attempting to call them on a UIWebView object. Try with this:
-(IBAction)searchButtonPressed:(id)sender{
NSLog(#"highlighttes");
[self highlightAllOccurencesOfString:#"不明"];
}
-(IBAction)clearHighlights:(id)sender{
[self removeAllHighlights];
}
This will at least compile.

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");
}