Since iOS 11 the "anchor" present in my webview are not working anymore.
I first thought it was time to migrate from UIWebView to WKWebview so I proceed, but this is still not working.
I can't find any response over the web.
Can any one help me please ?
Thanks in advance
UPDATE :
//anchor ?
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"11.0"))
{
NSArray * spliting = [stringUrl componentsSeparatedByString:#"#"];
if (navigationAction.navigationType == WKNavigationTypeLinkActivated && [spliting count] == 2)
{
NSString * anchor = spliting.lastObject;
//[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.location.hash = '#%#';",anchor]]; // not working in iOS11
NSString* code = [NSString stringWithFormat:#"el = document.getElementsByName(\"%#\")[0]; if (el) el.scrollIntoView();", anchor];
(void) [webView evaluateJavaScript:code completionHandler:nil];
}
}
Related
So I'm adding a search bar to my custom tableview with custom cells, and it's giving an error.
-[Game rangeOfString:options:]: unrecognized selector sent to instance 0x170244e60
2016-10-15 15:41:49.557956 CustomCellApp[25930:7889617]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Game rangeOfString:options:]: unrecognized selector sent to instance 0x170244e60
I'm populating my tableview by an array containing NSObjects which contain strings (gamesArray)and those strings I'm getting it from a JSON array (jsonArray), all from a php file connecting to a MYSQL server which have all the strings.
Here is the code for the search bar:
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if (searchText.length == 0) {
isFiltered = NO;
} else {
isFiltered = YES;
filteredGamesArray = [[NSMutableArray alloc] init];
// ----- Problem Method ----- //
for (NSString *str in gamesArray) {
// ----- Crashes Here ----- //
NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (stringRange.location != NSNotFound) {
[filteredGamesArray addObject:str];
}
}
// ------------------------------------ //
}
[myTableView reloadData];
}
Here is the code for the tableView:
// Configuring the cell
Game * gameObject;
// Showing either Normal List or Filtered List
if (!isFiltered) {
gameObject = [gamesArray objectAtIndex:indexPath.row];
}
else {
gameObject = [filteredGamesArray objectAtIndex:indexPath.row];
}
Here is the code from server
It adds the strings from the server to a jsonarray which is then added to an NSObject to an array called gamesArray
NSString * gID = [[jsonArray objectAtIndex:i] objectForKey:#"id"];
NSString * gName = [[jsonArray objectAtIndex:i] objectForKey:#"gameName"];
NSString * gLabel1 = [[jsonArray objectAtIndex:i] objectForKey:#"gameLabel1"];
NSString * gLabel2 = [[jsonArray objectAtIndex:i] objectForKey:#"gameLabel2"];
NSString * gLabel3 = [[jsonArray objectAtIndex:i] objectForKey:#"gameLabel3"];
Any help would be greatly appreciated!
How can I fix this? Any ideas? Thank you
I think the problem is that when searching, the program is seeing that it has an array to search through, gamesArray, but when going inside it has 5 NSObjects, each containing strings, so it's not working because it doesn't know what to do.
As a solution, how can I make it that the search bar searches through the gamesArray, directly at 1 NSObject, the gameName , reading all the strings in that NSObject which is called gName
For example, this piece of code targets a specific NSObject inside the gamesArray
[[gamesArray objectAtIndex:indexPath.row] valueForKey:#"gameName"];
My first guess is: objects in games array are not strings, they are Game objects.
for (Game *game in gamesArray) {
NSString *str = game.fieldOfInterest;
// ----- Crashes Here ----- //
NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (stringRange.location != NSNotFound) {
[filteredGamesArray addObject:game];
}
}
This should address the issue of your crash. If the search behavior is not correct, please ask a new question related to your new issue. As a best guess, I would suggest you inspect your table delegate methods for how they behave when filtered is true.
I am a newbie in OSx development.
I have a Cocoa application which uses a Webview. Everything is working fine, except for the textfield in the webview. I know how to enable keystrokes in NSTextField, but not the ones in the Webview. I've been searching the web all day, but with no luck.
I badly need some help on how to enable the keystrokes to implement keyboard shortcut keys.
Example:
copy -> command + c
paste -> command + v
cut -> command + x
Any help would be very much appreciated.
I got the answer now. I've realized that I forgot to implement
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
to the class which handles the Webview.
#Kimpoy, thanks for the reference to performKeyEquivalent!
For completeness, I implemented it this way...
Subclass your webview from WebView and implement the method:
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
NSString * chars = [theEvent characters];
BOOL status = NO;
if ([theEvent modifierFlags] & NSCommandKeyMask){
if ([chars isEqualTo:#"a"]){
[self selectAll:nil];
status = YES;
}
if ([chars isEqualTo:#"c"]){
[self copy:nil];
status = YES;
}
if ([chars isEqualTo:#"v"]){
[self paste:nil];
status = YES;
}
if ([chars isEqualTo:#"x"]){
[self cut:nil];
status = YES;
}
}
if (status)
return YES;
return [super performKeyEquivalent:theEvent];
}
Credit to #aventurella over here: https://github.com/Beats-Music/mac-miniplayer/issues/3. Just modified slightly to return the super response as default because it should propagate down to its subviews.
As a note, I'd recommend implementing a log or similar in your custom webview to make sure you really are working with your class:
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Drawing code here.
NSLog(#"Custom webview running...");
}
I have a small png that I am adding to a view which I am pretty sure I had working previously but suddenly stopped working on the iPad itself while continuing to work fine on the iPad simulator.
Here is the code I am using to add the image to the view...
UIImageView *bottomResizer = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"resizeLine.png"]];
bottomResizer.center = CGPointMake(bottomResizer.center.x, bottomResizer.center.y+self.frame.size.height-12);
bottomResizer.tag = 301;
[self addSubview:bottomResizer];
[bottomResizer release];
This occurs in a UIGestureRecognizerStateBegan event. The following code in removes the image in a touchesEnded event without any errors even though you cannot see it.
NSArray *subViews = [self subviews];
int count = [subViews count];
for (int i =count-1; i>=0; i--) {
if([[subViews objectAtIndex:i] tag] == 301) {
[[subViews objectAtIndex:i] removeFromSuperview];
}
}
I don't think it is anything I changed in my code since it works in the simulator. Not sure where to look next for the problem. I have reset the simulator to see if it would break after a reset. I have also cleaned the project.
Thanks.
John
Put a breakpoint AFTER this line UIImageView *bottomResizer = [[UIImageView alloc]...
Then on the console "po [bottomResizer image]"
If it is nil then either the resource is not getting copied correctly into the bundle OR you could have a corrupt image that the device cannot load.
Im trying to implement your implementation to my project as a button called 'Gallery" but receive an error when trying to run the project.
My implementation file looks like this.
-(IBAction) gallery{
NSMutableArray *photos = [[NSMutableArray alloc] init];
MWPhoto *photo;
{
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:#"fans1" ofType:#"jpg"]];
photo.caption = #"My fans 1";
[photos addObject:photo];
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:#"fans2" ofType:#"jpg"]];
photo.caption = #"My fans 2";
[photos addObject:photo];
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:#"fans3" ofType:#"jpg"]];
photo.caption = #"Fans3";
[photos addObject:photo];
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:#"fans4" ofType:#"jpg"]];
photo.caption = #"Fans4";
[photos addObject:photo];
}
self.photos = photos;
// Create browser
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.displayActionButton = YES;
//browser.wantsFullScreenLayout = NO;
//[browser setInitialPageIndex:2];
// Show
if (_segmentedControl.selectedSegmentIndex == 0) {
// Push
[self.navigationController pushViewController:browser animated:YES];
} else {
// Modal
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];
nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nc animated:YES];
}
}
#pragma mark - MWPhotoBrowserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
return _photos.count;
}
- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex: (NSUInteger)index {
if (index < _photos.count)
return [_photos objectAtIndex:index];
return nil;
}
When I run the project but the image gallery is not displayed. Im fairly new to ioS development.If you can please point me in the right direction i will deeply appreciate it. The main goal is to have the image gallery displayed when the user touches the Gallery button.
I copied and edited the code from the MWPhotoBrowser Demo Project File I don't receive any errors but I can't get the gallery to appear once button is touched. (BTW I assigned the IBACTION to the buttons). If there is another source code or alternative Framework I can use please advise. Thanks!
Some Ideas:
1) try using 'initWithPhotos'.
2) put a breakpoint at the place you are pushing, check that the push is called.
3) check that the navigationController is not null (0x0) in debugging.
4) remember to release 'browser'.
I have the problem depicted in the image when testing my app on a real device (iPhone 3G, 3.1.3).
It is fine in the simulator (xcode 3 with ios 4.1 sdk). sorry, can't post images yet, this is my first question here.
http://i.stack.imgur.com/Ct4on.jpg
I have the following code in the implementation of the annotation:
- (id)initWithLocation:(CLLocationCoordinate2D)coord {
self = [super init];
if (self) {
coordinate = coord;
}
return self;
}
And this is part of the header file:
#interface MyAnnotation : NSObject <MKAnnotation>
And this is where I create a new one (inside a loop):
MyAnnotation *theAnnotation = [[MyAnnotation alloc] initWithLocation:theCoordinate];
theAnnotation.title = [single objectForKey:#"address"];
theAnnotation.objID = [single objectForKey:#"id"];
[self.mapView addAnnotation:theAnnotation];
[theAnnotation release];
Any ideas about this? I don't know what to look :/
You could try to bring the (annotation)view to the front, when tapping on it.
So, when someone taps on an annotation, you should call [[self superview] bringSubviewToFront:self];
Best,
Christian