text from UITextField to UIWebView function - ios

I want to add search theWebView for UIWebView, and i need to put search query from UIWebView to the function of button:
-(IBAction)searchButtonPressed:(id)sender{
[theWebView highlightAllOccurencesOfString:#"%#", searchR];
}
ViewController.h:
#interface ViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate> {
IBOutlet UIWebView *theWebView;
IBOutlet UITextField *searchF;
IBOutlet UILabel *searchR1;
NSString *searchR;
}
#property (retain, nonatomic) IBOutlet UIWebView *theWebView;
#property (retain, nonatomic) IBOutlet UITextField *searchF;
-(IBAction)searchButtonPressed:(id)sender;
-(IBAction)clearHighlights:(id)sender;
ViewController.m:
#import "ViewController.h"
#import "SearchWebView.h"
#implementation ViewController
#synthesize theWebView;
#synthesize searchF;
-(IBAction)searchButtonPressed:(id)sender{
[searchF resignFirstResponder];
searchR = searchF.text;
searchR1.text = [[NSString alloc] initWithFormat:#"%#", searchR];
/*[theWebView highlightAllOccurencesOfString:#"%#", searchR];
[theWebView highlightAllOccurencesOfString:#"7019"];*/
}
-(IBAction)clearHighlights:(id)sender{
[theWebView removeAllHighlights];
}
This is my try, but it don't work!
Help please

Related

cannot find protocol declaration for delegate

these 2 are the files where i m creating a protocol and then declare the delegate in another class
this is my favouriteViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"
#class FavouritesTableViewController;
#protocol FavouritesTableViewControllerDelegate<NSObject>
- (void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item;
#end
#interface FavouritesTableViewController : UITableViewController <UISearchControllerDelegate,UISearchBarDelegate>
#property (strong, nonatomic) IBOutlet UISearchController *search;
#property (strong, nonatomic) IBOutlet UITableView *table;
#property (nonatomic, weak) id < FavouritesTableViewControllerDelegate > delegate;
#end
and this is my viewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "FavouritesTableViewController.h"
#interface ViewController : UIViewController <CLLocationManagerDelegate,FavouritesTableViewControllerDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *weatherIcon;
#property (weak, nonatomic) IBOutlet UILabel *Place;
#property (weak, nonatomic) IBOutlet UILabel *Temperature;
#property (weak, nonatomic) IBOutlet UILabel *unit;
#property (weak, nonatomic) IBOutlet UILabel *weatherText;
#property (weak, nonatomic) IBOutlet UITextView *Info;
#property (weak, nonatomic) IBOutlet UILabel *summary;
#property (strong,nonatomic) NSString *longitude;
#property (strong,nonatomic) NSString *latitude;
#property (strong,nonatomic) NSString *locationName;
#property BOOL setLocation;
#property (weak, nonatomic) IBOutlet UIScrollView *scroll;
- (IBAction)forecast:(UIButton *)sender;
- (IBAction)Share:(UIButton *)sender;
- (IBAction)history:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activIndicator;
- (IBAction)favbutton:(id)sender;
#end
the error i get is
:- Cannot find protocol declaration for
'FavouritesTableViewControllerDelegate'
I'm declaring these methods and protocols to pass data from FavouriteViewController to ViewController
and this is the protocol method which i call in ViewController.m
-(void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item
{
controller.delegate = self;
self.latitude = [item[0] valueForKey:#"lat"];
self.longitude = [item[0] valueForKey:#"long"];
self.locationName = [item[0] valueForKey:#"name"];
self.setLocation = YES;
[self viewDidLoad];
}
Ths is happening because of recursive import, in FavouritesTableViewController you are importing "ViewController.h" and again ViewController.h you are importing "FavouritesTableViewController.h"
try
#class viewController;
#class FavouritesTableViewController;
in FavouritesTableViewController.h and remove "#import ViewController.h"

How come "self.canDisplayBannerAds = YES;" makes app crash on iOS 8?

I would like to point out that self is a WelcomeViewController and that it inherits from UIViewController :
WelcomeViewController.h
#import <UIKit/UIKit.h>
#interface WelcomeViewController : UIViewController
#property (strong, nonatomic) NSString* score;
#property (strong, nonatomic) NSUserDefaults* preferences;
#end
WelcomeViewController.m
#import "WelcomeViewController.h"
#import "GESceneController.h"
#import <iAd/iAd.h>
#interface WelcomeViewController ()
#property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
#property (weak, nonatomic) IBOutlet UILabel *highScoreLabel;
#end
#implementation WelcomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.canDisplayBannerAds = YES;
[self.scoreLabel setText:self.score];
NSString* highScoreText = [NSString stringWithFormat:#"Meilleur score : %ld",
[self.preferences integerForKey:#"highscore"]];
[self.highScoreLabel setText:highScoreText];
// Do any additional setup after loading the view.
}
and I get the error : [WelcomeViewController setCanDisplayBannerAds:]: unrecognized selector sent to instance 0x7d97f080
Have you imported the iAd file into your linked frameworks and libraries? If not, goto your build info and scroll all the way to the bottom, there you will find 'linked frameworks..' and add the framework into you app.

Pass value from controller to controller

I'm building my first iOS app to try and learn iOS coding. However, I need to pass a value xAuthToken from one controller to the other. I can't seem to get it working to. I init the value in the first controller ViewController, but then I need it in SettingsController. I keep getting errors and the one it throws now is: Property 'ViewController' not found on object of type 'ViewController'
What am I doing wrong?
ViewController.h
#import <UIKit/UIKit.h>
#import "SettingsController.h"
#interface ViewController : UIViewController <UITextFieldDelegate>
#property (weak, nonatomic) IBOutlet UITextField *txtUsername;
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)sigininClicked:(id)sender;
- (IBAction)backgroundTap:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic) NSString *xAuthToken;
#end
#implementation ViewController
- (IBAction)sigininClicked:(id)sender {
NSString *xAuthToken = #"0";
self.viewController = [[SettingsController alloc] init];
self.viewController.xAuthToken = xAuthToken;
[self performSegueWithIdentifier:#"login_success" sender:self];
}
SettingsController.h
#import <Foundation/Foundation.h>
#interface SettingsController : UIViewController
#end
SettingsController.m
#interface SettingsController ()
#property (weak, nonatomic) IBOutlet UITextField *myTextField;
#property (weak, nonatomic) IBOutlet UISwitch *mySwitch;
#end
#implementation SettingsController
//THIS IS WHERE I NEED XAUTHTOKEN
If you have a segue that presents your SettingsController, pass the information it needs in prepareForSegue. Don't create a new local SettingsController.
You can do something like
viewController = [self.storyboard instantiateviewcontrollerwithidentifier:#"your vc name"];
viewController.Xauthtoken = data;
// Do something else with this.
Or another way ( I don't know if it's good or bad, use it while your vc is already active ):
Use NSNotificationCenter and pass values between it.
Third way is create delegate for first Viewcontroller.
Try this in your ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic) NSString *xAuthToken;
#end
#implementation ViewController
- (IBAction)sigininClicked:(id)sender {
xAuthToken = #"Your Value Here";
[self performSegueWithIdentifier:#"login_success" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"login_success"]) {
SettingsController *destViewController = segue.destinationViewController;
destViewController.xAuthToken = xAuthToken;
}
}
And in your SettingsController.h
#import <Foundation/Foundation.h>
#interface SettingsController : UIViewController
#property (nonatomic,strong) NSString *xAuthToken;
#end
SettingsController.m
#interface SettingsController ()
#property (weak, nonatomic) IBOutlet UITextField *myTextField;
#property (weak, nonatomic) IBOutlet UISwitch *mySwitch;
#end
#implementation SettingsController
-(void)viewDidLoad{
NSLog("%#",xAuthToken);
}

UILabel text property iOS

I would like to modify the text property of a UILabel (nameLbl) but don't know what i am wrong.
I have 2 Views, the first is a ViewController, the second is ProfileViewController. The ProfileViewController fill some field of user profile this data are passed to ViewController and showed in UIlabel.
The issue is I can't show the datas in the ViewController.
What am I get wrong?
---ViewController.h---
#interface ViewController : UIViewController
{
IBOutlet ViewController *profile;
IBOutlet UILabel *nameLbl, *celLbl, *cfLbl;
IBOutlet UITextField *nameTF;
}
#property (nonatomic, retain) IBOutlet ViewController *profile;
#property (retain, nonatomic) IBOutlet UILabel *nameLbl, *celLbl, *cfLbl;
#property (nonatomic, retain) IBOutlet UITextField *nameTF;
-(void) setUser: (NSString *) name:(NSString *) cel:(NSString *) cf;
#end
---ViewController.m---
#synthesize nameLbl, celLbl, cfLbl;
-(void) setUser:(NSString *)name:(NSString *)cel:(NSString *)cf
{
nameLbl = [[UILabel alloc] init];
[nameLbl setText:name];
}
this is the connection inspector
https://drive.google.com/file/d/0Bz7WcQmZNuFLMWt3QUo1Tk5XUW8/edit?usp=sharing
Remove
nameLbl = [[UILabel alloc] init];
from your code it seems that the nameLbl UILabel has already been initialized from nib, and you are creating a new memory reference, so its not working.

modal segue won't engage due to instance selector [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have twoo buttons underneath the view controller. One of those buttons makes calculations. The second one shows information about these calculations. For the information I' m using a modal segue to another viewcontroller called werkwijzeViewController. The calculations button doesn't pose problems. On pressing the information button I get "UIStoryboardModalSegue popoverController]: unrecognized selector sent to instance". What's wrong? I'm uploading some of the relevant code:
viewcontroller.h
#import <UIKit/UIKit.h>
#import "breuk.h"
#import "verklaringViewController.h"
#interface ViewController : UIViewController <UIPopoverControllerDelegate>
#property (strong, nonatomic) IBOutlet UITextField *tellerVeld1;
#property (strong, nonatomic) IBOutlet UITextField *noemerVeld1;
#property (strong, nonatomic) IBOutlet UILabel *quotientVeld;
#property (strong, nonatomic) IBOutlet UITextField *tellerVeld2;
#property (strong, nonatomic) IBOutlet UITextField *noemerVeld2;
#property (strong, nonatomic) IBOutlet UIButton *berekenKnop;
#property (strong, nonatomic) breuk *breuk1;
#property (strong, nonatomic) breuk *breuk2;
#property (strong, nonatomic) breuk *hoofdbreuk;
#property (strong, nonatomic) IBOutlet UITextField *uitkomstNoemerVeld;
#property (strong, nonatomic) IBOutlet UITextField *uitkomstTellerVeld;
#property (strong, nonatomic) IBOutlet UILabel *uitkomstStreep;
#property (strong, nonatomic) UIPopoverController *popoverController;
- (IBAction)berekenQuotient:(id)sender;
#end
viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
{
BOOL veldVerplaatst;
}
#end
#implementation ViewController
#synthesize tellerVeld1;
#synthesize noemerVeld1;
#synthesize quotientVeld;
#synthesize tellerVeld2;
#synthesize noemerVeld2;
#synthesize berekenKnop;
#synthesize uitkomstNoemerVeld;
#synthesize uitkomstTellerVeld;
#synthesize uitkomstStreep;
#synthesize breuk1;
#synthesize breuk2;
#synthesize hoofdbreuk;
#synthesize popoverController;
...
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue=(UIStoryboardPopoverSegue *)segue;
UIPopoverController *popoverController;
popoverController = popoverSegue.popoverController;
popoverController.delegate = self;
verklaringViewController *verklaringVC;
verklaringVC=(verklaringViewController *)popoverController.contentViewController;
...
}
#end
werkwijzeViewController.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface werkwijzeViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIButton *af;
#property (strong, nonatomic) IBOutlet UITextView *vereenvoudigBreuken;
#property (strong, nonatomic) IBOutlet UITextView *vermenigvuldigBreuken;
#property (strong, nonatomic) NSMutableArray *tabelTellerOntbonden;
#property (strong, nonatomic) NSMutableArray *tabelNoemerOntbonden;
#property (strong, nonatomic) NSMutableArray *tabelGgdOntbonden;
#end
werkwijzeViewController.m
#import "werkwijzeViewController.h"
#interface werkwijzeViewController ()
#end
#implementation werkwijzeViewController
#synthesize tabelGgdOntbonden;
#synthesize tabelNoemerOntbonden;
#synthesize tabelTellerOntbonden;
...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
tabelTellerOntbonden =[NSMutableArray new];
tabelTellerOntbonden = [((ViewController *)self.presentingViewController).breuk1 ontbindInFactoren:((ViewController *)self.presentingViewController).breuk1.tellerBreuk inTabel:tabelTellerOntbonden];
NSLog(#"%#",tabelTellerOntbonden);
}
#end
breuk.m
#import "breuk.h"
#implementation breuk
#synthesize tellerBreuk;
#synthesize noemerBreuk;
#synthesize origineleNoemerBreuk;
#synthesize origineleTellerBreuk;
#synthesize ggd;
#synthesize quotientBreuk;
...
- (NSMutableArray *)ontbindInFactoren:(int)product inTabel:(NSMutableArray *)tabel
{
for (int priemfactor=1; priemfactor<=product; priemfactor++)
{
while (product%priemfactor==0)
{
[tabel addObject:[NSString stringWithFormat:#"%i",priemfactor]];
}
}
return tabel;
}
#end
You should post the code for all of your IBAction methods tied to your two buttons.
As a glance, it looks to me like the problem is that your prepareForSegue method blindly casts your segue to type UIStoryboardPopoverSegue, and then tries to access the segue's popoverController property.
Your prepareForSegue method will be called for every segue. You need code in your prepareForSegue that checks the segue identifier to make sure you are dealing wit the correct segue before casting it to a UIStoryboardPopoverSegue.

Resources