My app uses UIWebview, and it works well in iOS 5 and iOS 6. However, it doesn't load the webpage in iOS 7 when I build in Xcode 5 and run the same code.
- (void)webViewDidFinishLoad:(UIWebView *)webView {}
- (void)webViewDidStartLoad:(UIWebView *)webView {}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {}
All delegate function is not called. But I do set delegate in xib file and code
self.theWebView.delegate = self;
I didn't find any information via google. Thank you for your help.
I moved the loadRequest method to the completion handler of a presentViewController and it works in iOS 5, 6 and 7:
[self presentViewController:gwvc animated:YES completion:^(void){
[gwvc.wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.walkjogrun.net/about/eukanuba.html"]]];
}];
I found the root cause.
maybe I incorrectly used UIWebView, but it works in iOS5 and iOS6.
I don't know why it works in earlier iOS versions...
Moreover, it works in iOS7 when I build code with SDK 6.1.
Here's my old code.
RechargeWebPageViewController *webPageViewController;
webPageViewController = [[ RechargeWebPageViewController alloc] initWithNibName:#"WebPage" bundle:nil];
if (webPageViewController != nil) {
webPageViewController.hidesBottomBarWhenPushed = YES;
webPageViewController.delegate=self;
[self.navigationController pushViewController:webPageViewController animated:YES];
NSURL *url = [NSURL URLWithString:#"https://xxx.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[webPageViewController loadRequest:request];
[request release];
}
I moved the loadRequest from the viewDidLoad method to the ViewWillAppear method, then it worked.
I think maybe UIWebView is not initialized correctly in my old code for iOS7.
Related
Just came across a bug in MapKit, wanted to see what the community is experiencing. When adding a MKUserTrackingBarButtonItem to a UIToolBar, I'm seeing the map is not releasing from memory when switching to another viewController (though I see the dealloc is firing).
Can anyone confirm they are seeing this behavior? My testing shows the map releases properly if I do not add MKUserTrackingBarButtonItem. Using iOS7, testing with Instruments/Leaks.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
MKUserTrackingBarButtonItem *userTrackingBarButtonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
[userTrackingBarButtonItem setAction:#selector(track:)];
UIBarButtonItem *flexibleSpaceBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:flexibleSpaceBarButton, userTrackingBarButtonItem, flexibleSpaceBarButton, nil] animated:YES];
[self.navigationController setToolbarHidden:NO animated:NO];
}
MKUserTrackingBarButtonItem and the MKMapView each hold strong references to each other, resulting in a circular retain. This appears to be a bug in MapKit itself, and it's still present in iOS 7.1.
A solution is to add a dealloc to your view controller that contains the MapView:
-(void)dealloc
{
userTrackingBarButtonItem.mapView = nil; // Circular reference bug workaround
}
I had developed an ios app for ios 4.0.That was navigation based application.Now I want it also support for iPhone-5 I think I changed xib after checking device version,I am facing problem xib is changed but it's view Height is not changed.How it can possible if some else face this problem please share ideas with me.Thanks.
IN APP Delegate:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
//----------------HERE WE SETUP FOR IPHONE 4/4s/iPod----------------------
if(iOSDeviceScreenSize.height == 480){
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_4inch" bundle:nil];
NSLog(#"iPhone 4: %f", iOSDeviceScreenSize.height);
}
//----------------HERE WE SETUP FOR IPHONE 5----------------------
if(iOSDeviceScreenSize.height == 568){
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_5inch" bundle:nil];
NSLog(#"iPhone 5: %f", iOSDeviceScreenSize.height);
}
return YES;
}
Its Works !!!!!!
Set iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this.
Get started with Auto Layout here:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2
If you still want to support iOS 4.0, have separate .xib files for different screen sizes and load them appropriately at launch.
To load different nib files based on your screen size, in your app delegate, you will need to add/replace the following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_4inch" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}
where ViewController_4inch is the name of the nib file that is designed for iPhone 5 screen
I have had one issue with Core Data and Relationship. Since this has kept me without a solution for a while and has at the same time been easy to locate I have made a tiny sample application to reproduce the problem.
Under XCode I created a barebone Window-based application, checking "Use Core Data for storage".
I called this application "CDR" for Core-Data-Relationship.
I then added a subclass of UIViewController called CDR_ViewController; as I usually do.
Here is the relevant code that I added :
First in CDR_ViewController.h :
#import <UIKit/UIKit.h>
#import "AppDelegate_Shared.h"
#interface CDR_ViewController : UIViewController {
UILabel *cdrLabel;
NSManagedObject *currentItem;
}
#property (nonatomic, retain) IBOutlet UILabel *cdrLabel;
-(IBAction) handleButtonClick:(id)sender;
#end
Then in CDR_ViewController.m the viewDidLoad method is as follow :
- (void)viewDidLoad {
[super viewDidLoad];
NSFetchRequest *request;
NSError *error;
AppDelegate_Shared *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
request=[[NSFetchRequest alloc] init];
[request setEntity: [NSEntityDescription entityForName:#"CDR_Entity" inManagedObjectContext:context]];
error=nil;
NSUInteger count = [context countForFetchRequest:request error:&error];
[request release];
if (count!=0) {
request=[[NSFetchRequest alloc] init];
[request setEntity: [NSEntityDescription entityForName:#"CDR_Entity" inManagedObjectContext:context]];
error=nil;
NSArray *objects=[context executeFetchRequest:request error:&error];
NSLog(#"Error:%#",error);
[request release];
currentItem=[objects objectAtIndex:0];
return;
}
NSManagedObject *newItemOne,*newItemTwo,*newItemThree;
request=[[NSFetchRequest alloc] init];
[request setEntity: [NSEntityDescription entityForName:#"CDR_Entity" inManagedObjectContext:context]];
newItemOne=[NSEntityDescription insertNewObjectForEntityForName:#"CDR_Entity" inManagedObjectContext:context];
newItemTwo=[NSEntityDescription insertNewObjectForEntityForName:#"CDR_Entity" inManagedObjectContext:context];
newItemThree=[NSEntityDescription insertNewObjectForEntityForName:#"CDR_Entity" inManagedObjectContext:context];
[newItemOne setValue:[NSNumber numberWithInteger:1] forKey:#"Value"];
[newItemTwo setValue:[NSNumber numberWithInteger:2] forKey:#"Value"];
[newItemThree setValue:[NSNumber numberWithInteger:3] forKey:#"Value"];
[newItemOne setValue:newItemThree forKey:#"Previous"];
[newItemOne setValue:newItemTwo forKey:#"Next"];
[newItemTwo setValue:newItemOne forKey:#"Previous"];
[newItemTwo setValue:newItemThree forKey:#"Next"];
[newItemThree setValue:newItemTwo forKey:#"Previous"];
[newItemThree setValue:newItemOne forKey:#"Next"];
error=nil;
[context save:&error];
[request release];
currentItem=newItemOne;
}
And the viewWillAppear method is as follow :
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
cdrLabel.text=[NSString stringWithFormat:#"%#",[currentItem valueForKey:#"Value"]];
}
Finally the handleButtonClick method is as follow :
-(IBAction) handleButtonClick:(id)sender
{
if (((UIButton*)sender).tag==101) {// Previous item.
currentItem=[currentItem valueForKey:#"Previous"];
} else /*(((UIButton*)sender).tag==102)*/ {// Next item.
currentItem=[currentItem valueForKey:#"Next"];
}
cdrLabel.text=[NSString stringWithFormat:#"%#",[currentItem valueForKey:#"Value"]];
}
The CDR_ViewController.xib contains one Label and two buttons.
This code works fine for start, meaning just after I compile the app and reset the contents of the iPhone simulator.
I can then cycle the contents of the label : 1,2,3,1,2,3,1,2,3 ---etc… and backward with the buttons.
As soon as I terminate the application using Command-Q. When I want to start it again, it crashes on :
currentItem=[currentItem valueForKey:#"Previous"];
or:
currentItem=[currentItem valueForKey:#"Next"];
inside the handleButtonClick method.
And it is the same when I put the app on my iPod touch.
Can anyone see in my code anything that could explain this behavior?
If you terminate an app in the simulator by stopping it, a opposed to clicking the home button in the simulator or otherwise, then the program is sent a SIGKILL message which immediately stop it running. Your application delegate methods (will terminate, will enter background etc) will not be called.
In all likelihood this will have meant that your managed object context has not been saved, so when re-running the app the object graph cannot be restored properly. In your sample app, add another button which saves the context. If you click this button, then terminate your app, does that solve the problem?
I have created navigation based project. and in second screen i want to add uitabbarcontroller. so can any one suggest how i do this.
i already did lot of search but no success yet. so please can you provide a simple sample of this. i already tried below discussion but i think its not a good approach.
Navigation Based Application with TabBar
Thanks
Actually this is the correct approach. The one thing that is not correct is where the controllers are allocated. This is happened in the previous controller, the one that is making the push, but should be allocated in the object that is responsible, the TabBarController.
When you implement your action to show the UITabBarController make the following code:
- (void) theAction {
SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
Then when you implement the SomeTabBarControllerSubClass class:
(.h)
#interface SomeTabBarControllerSubClass : UITabBarController {
UIViewController *first;
UIViewController *second;
}
#end
(.m)
#implementation SomeTabBarControllerSubClass
- (void) viewDidLoad {
first = [[UIViewController alloc] init]; //Or initWithNib:
second = [[UIViewController alloc] init];
first.view.backgroundColor = [UIColor greenColor] //Just example
second.view.backgroundColor = [UIColor redColor] //Just example
first.tabBarItem.image = [UIImage imageNamed:#"someImage.png"];
self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
}
- (void) dealloc {
[first dealloc];
[second dealloc];
[super dealloc];
}
#end
Does somebody know why this code is crashing somewhere in the release pool (after 'eject' is called)?
I saw in AVPlayer class reference that the 'currentItem' property is NOT declared as 'retain' http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009530-CH1-SW21
Is it a bug in the AVPlayer class or should I retain it somewhere else?
Thanks!
- (void) viewDidLoad {
NSURL *url = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
playerItem = [[AVPlayerItem alloc] initWithURL:url];
player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
}
- (IBAction) eject {
[player release];
[playerItem release];
}
I typically use this to setup a player:
if (!self.player) {
player = [[AVPlayer alloc] init];
}
[self.player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:videoURL]];
I believe that AVPlayer retains AVPlayerItem in initWithPlayerItem: function, so you are possibly leaking memory with your AVPlayerItem. "currentItem" is readonly property and should not be "retain" which is only for writable properties.