I have created a nib file and added a UIWebView. i created an IBOutlet and attached web view with that outlet. till here everything is fine . now when i set the delegate of that webview to self in ViewDidLoad, and implement two of its delegate methods. the application crashes, i m not writing anything in the methods , i have just implemented and the application is crashing ....
what could b the problem ?
is there any problem ???
There is a problem if one of the delegate methods is
– webView:shouldStartLoadWithRequest:navigationType:
Indeed, this method returns a BOOL (YES if the web view should begin loading content; otherwise, NO). Therefore, since you are not writing any code inside the method, this may cause a problem. Try inserting in this method the statement
return YES;
The other delegate methods return void, so these should not be the cause of the problem.
Related
I have 2 xibs, one for iPad and one for iPhone.
However, currently I have only one view controller for those 2 xibs that works for both iPhone&iPad.
Inside my iPad Xib I have an IBOutlet that doesn't belong to the iPhone xib.
How should I define that outlet ?
I notice that if I put inside my deallc method, something like this :
-(void) dealloc
{
[outletOnlyForIpad release]
}
The app crashes on the iPhone. Apparently cause it doesn't instantiates well on the iPhone. (I hoped it would stay nil, but it's not the case)
I didn't find any preprocessor macro that I can use so I can declare that Outlet only for iPad.
Is the only way to do it is by checking in runTime something like :
isIpad()
[outletOnlyForIpad SomeMethodOnTheOutlet]
In every place in my controller ?
Your code is correct. That outlet should be staying nil, so sending it a release message should be harmless. Rather than work around the error, I suggest you check where this outlet is being set and fix the cause of the problem. Are you certain you aren't connecting anything to it in the iPhone nib?
You have to check at run-time for the device and handle the outlets then if you want separate outlets.
If I create an app with different controls on different devices, I tend to create them programmatically to avoid connection problems such as this.
in your dealloc to avoid the crash on iPhone, and connect the IBOutlet as usual in your iPad xib:
-(void) dealloc
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[outletOnlyForIpad release]
}
}
When you initialize your class, all instance variables are automatically initialised to zero. Thus this is the equivalent of adding:
outletOnlyForIpad = nil;
To your init method.
This nil value will be overwritten when the view loads for the iPad but not the iPhone (unless you have other code that sets it). However your [outletOnlyForIpad release] crash shows that outletOnlyForIpad is not nil at this point, which means that something has given it a value. You need to find out what this something is - it may be your interface builder file.
I have a UITableViewController, nib based, that is presented in a UIPopoverController when running on iPad and presented 'natively' when running on iPhone.
When running on the iPad, the self.tableView property of the controller is nil throughout it's lifecycle. The delegate messages that pass in the tableView as part of their normal operation work fine and have a reference to a table view.
On the iPhone, the property is set and the reference is valid as you would expect.
Anything specific that can cause the self.tableView property to be nil? I've double checked the connections in Interface Builder - the Nib just contains a table view and the related UISearchBar stuff. The table view in the Nib is set as the view controller's view.
This is on 4.2.1 on both devices. Banging my head on this and can't find my error.
I figured out my problem and of course, it's a programming error.
In this case, an errant #synthesize tableView at the top of the implementation file, generating conflicting getters and setters.
Apologies and thanks for those that looked at this.
Try this... in one of the methods that returns the tableView object do "assert(self.view == tableView);" and see what happens. If the assert doesn't fire, and I suspect that it wont fire in either the iPhone or iPad, then simply cast self.view into a UITableView and do what you need to do.
I have a UIWebView named wView. I want to use webViewDidFinishLoad: in my class, so I am setting the class as the delegate for wView by using this line:
wView.delegate = self;
Everything loads properly, but when I close the UIWebView, the App crashes. If I comment out the wView.delegate = self, it works and does not crash, but then I can't use webViewDidFinishLoad: - any ideas? Do I need to release something?
The UIWebView Reference says:
Important: Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.
Ensure to set the delegate to nil (wView.delegate = nil). This will prevent webview from trying to access and call methods on a dealloc'd view controller, which would result in a crash.
The iphone program is set up in the Utility Application model where you have a root view and two subviews (mainViewController & flipsideViewController) which are outlets.
If I try to set the UISwitch at rootViewController's viewDidLoad (with [flipsideViewController.switchInstance setOn:YES]), it doesn't work.
Within flipsideViewController, that method works but not outside of it. Any idea why? I can pass other methods...
Even if I pass a method to the flipsideViewController that then does the setOn method, it still doesn't work...
Any ideas?
Just as a 'sanity-check' (as others have put it to me) have you made sure your flipsideViewController variable is not null at the time you are calling the above code?
I have a UITableView populated with a location-based datasource. I'm calling [self updateView]; to manually refresh the view after the location is found which works fine...but for some reason the didSelectRowAtIndexPath method isn't getting called. Any ideas of why it's not working?
Code snippet: http://pastie.org/464300
Ensure that the delegate property of your tableView is set.
slf said:
Make sure it's defined in your .h
file. The protocol does a
'doesRespondToSelector' first and if
you aren't making it public through
your header the message my fail
-respondsToSelector: will detect methods that are not exposed in the interface.