I have a reader app that loads .epub files and usually I have no problem with selection at all, lately I have integrated fixed layout .epub files but I'm facing a problem: when I have a box containing one line the selection works fine, but when the box contains several lines, meaning several <p></p>, I cannot select a single word from the box. On selection the whole box gets selected as shown in the screenshot. When I try the same .epub file on iBooks, the selection works fine on all text. Any idea how I can fix the issue?
Here is the code for loading the file on UiWebView.
NSString *contents = [NSString stringWithContentsOfFile:itemPath encoding:NSUTF8StringEncoding error:nil];
if (!contents) {
contents = [NSString stringWithContentsOfFile:itemPath encoding:NSASCIIStringEncoding error:nil];
}
[readingWebView loadHTMLString:contents baseURL:baseURL];
I have finally got the answer.
When using this function:
NSString *jsString = [NSString stringWithFormat:#"document.getElementsByTagName('body')[0].webkitTextSizeAdjust= '%d%%'", font];
to set the font size some restrictions are set on the web view, one of them is related to the selection with fixed layout epubs.
I used instead:
NSString *jsString = [NSString stringWithFormat:#"document.getElementsByTagName('body')[0].style.fontSize= '%d%%'", font];
Related
I have a newb question, which I have tried unsuccessfully to find answers for on the web. The task is simple: I want to create a core data document-based app but alter the values in some label objects. Using interface builder, I can build the core data model and populate it, using an array controller, table, etc. all without writing any code. So far so good. My test example is to build a core data model with Box entities that have length and width attributes. I would like a label to display the area, i.e. length*width for any geometrically challenged :).
So after browsing around, I've decided I need to create an NSWindowController subclass and use that to update the label when a box in the table is selected. Have attempted this, but have failed. Before I even hook up the label to the window controller, I have a problem. Following the template comments, I added this to Document.m:
- (void)makeWindowControllers
{
NSLog(#"Adding custom Window Controller");
MyWindowController* myWindowController = [[MyWindowController alloc] init];
[self addWindowController:myWindowController];
}
Also added this to the template MyWindowController.m:
- (id)init
{
self = [super initWithWindowNibName:#"MyWindowController"];
return self;
}
The window controller has its own NIB file from Interface builder where I put the table and label etc. The file owner is set to MyWindowController. Probably forgetting other things, but that's what I remember for now.
The log message appears at startup, but then I get an exception "this class is not key value coding-compliant for the key managedObjectContext" before the window appears. I'm guessing that I don't have the window controller hooked up to the document class properly? My other thought is that the array controller is in the window controller nib, not the document nib, so maybe it's looking in the wrong place for the managedObjectContext?
I would try a different approach: Add area to your Box entity as a read-only attribute. Auto-create a Box class with Xcode ("Create NSManagedObject Subclass" menu item in the "Editor" menu when viewing the data model), then add this to Box.h
#property (weak, readonly) NSString * area;
and this to Box.m
- (NSNumber *)area
{
return [NSNumber numberWithDouble:([[self length] doubleValue] - [[self width] doubleValue])];
}
+ (NSSet *)keyPathsForValuesAffectingArea
{
return [NSSet setWithObjects:#"length", #"width", nil];
}
If you do this you can just bind area to a label value like you do for the other Box properties. No need to subclass NSWindowController or watch for changes.
I have inherited an iOS app that has not been maintained since iOS 3 era. The app relies on a web view to display some data. One of the feature is displaying the video in a full screen mode. What the client needs is a video reacting to the device rotation but all other views should be only portrait.
I've managed to figure out all the window.rootViewController and shouldAutorotate changes. I get the app to rotate only when I want. The problem I am facing is the video rotation 'too much'.
If I rotate the device left, the video rotates by 180 degrees (it goes into upside down orientation). Rotating back to the right causes the view width to shrink by half but the orientation is correct. I am not quite sure where the problem could be.
Anyone had similar issues?
I did have the same problem by inheriting a project. In my case, the application is navigation based, and the problem was that the main UINavigationController's view was being added as a subview of an UIViewController's view.
So, initially I had this code on my application:didFinishLaunchingWithOptions::
self.viewController = [[MyViewController alloc] init];
self.window.rootViewController = self.viewController;
and this on MyViewController's viewDidLoad:
UINavigationController *navController = [[UINavigationController alloc] init];
[self.view addSubview:navController.view];
Then I simply changed my application:didFinishLaunchingWithOptions: to this:
self.viewController = [[MyViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
I hope this helps you!
My App has 2 tabs (tabA and tabB), based on location the I set the navigationItem.titleView of tabB to a UIImageView when - viewWillAppear: is called.
The default behaviour of tabB is to simply display a title, e.g:
The issue is when the location changes and I remove the UIImageView navigationItem.titleView (using - removeFromSuperview), the default title has also disappeared and trying to set it with:
self.navigationItem.title = #"TITLE";
Does not work. Any ideas on how to solve this?
Simply setting:
navigationItem.titleView = nil;
Will restore the text title.
I am creating an application which displays map using MKMapView control. I have a button on the map that takes me to different view (information view) using the following code:
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
self.view = infoViewController.view;
Now after going to the information view I want to go back again to the main view which displays the map without having to loose anything. Is NagivationControlller my best option to use in this scenario?
Try this,
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
[self.navigationController pushViewController:infoViewController animated:YES];
[infoViewController release];
once you push viewController back button is available to come back to rootViewController.
I want to get the particular image name by touching inside of that image. Can any one give me the sample code for that?
Nick Weaver is correct. There is still a way to do it, though.
Create an array with the names of the images. Set the tag property of each UIImageView so it corresponds to the names in the array. Then, access the array via the tag property.
NSArray *nameArray = [NSArray arrayWithObjects:#"image1", #"image2", nil];
//touch happened
NSString *imageName = [nameArray objectAtIndex:imageView.tag];
Another method is creating a UIImageView subclass.
UIImageView nor UIImage do store the name of the image you have used to create the image. You can subclass UIImageView and use your own initializer and an extra field to store the name.