How to set iAd Delegate to new View Controller - delegates

I am developing an application using Xcode 7 and Swift 2. I recently discovered an error in my code. In the debugger log (I think that is what it is called) , it printed this:
[AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=7 "Ad was unloaded from this banner" UserInfo={ADInternalErrorCode=7, NSLocalizedFailureReason=Ad was unloaded from this banner, ADInternalErrorDomain=ADErrorDomain}
I did some research and found out that I needed this code:
iAdBannerView.delegate = self
In my viewDidLoad method. I tried it, and I no longer recieved the error. However, I have two viewControllers. Both contain iAds. In the original view controller, ViewController.swift, the code workds. In the view controller that I later added, AboutViewContoller, I get this error:
Cannot assign a value of type 'AboutViewController' to a value of type 'ADBannerViewDelegate?"
Could someone please show me my error in my code?

Earlier, I had:
class AboutViewController: UIViewController {
I forgot the ADBannerViewDelegate. The correct code is:
class AboutViewController: UIViewController, ADBannerViewDelegate {
Thanks to Charles A. and Daniel Storm for helping out!

Related

Cocoa Bindings on macOS

I learn Cocoa Bindings on macOS https://www.raywenderlich.com/921-cocoa-bindings-on-macos#toc-anchor-009,but I use xcode13 and swift5,I do this step by step,but The first step is to bind the array controller to the table view,I find something wrong.enter image description here,but in my project ,I cann't find this selector "SearchResultsController" like this picture enter image description here.if I ignore this problem and choose the "Array Controller" go on,Repeat the above process for Publisher TextField (Bind) by binding the value of this element to objectValue.artistName. build and run ,I will get error"Thread 1: EXC_BREAKPOINT (code=1, subcode=xxxx",I try many times just find the "Bind to"and "Model Key Path" value wrong.Can anyone tell me why? what does these two options mean?
I solve this problem.I set the NSArray Controller bind to View Controller and model key Path = "people"(this people is a array defined by myself),when get the request Data,append it to people. So it works success!But I don't know the real reason.I doubt that NSArray Controller must bind to a exist array,because the error with it doern't bind to .

Is setMainFrameURL really defined in webView

I'm new to programming with cocoa. I was going to experiment with the webkit View class. According to this page:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/index.html
a web view should have a method called "setMainFrameURL". However, when I try to use it, I get an error message saying that the method is not defined. How is this possible? Does this method really exist?
setMainFrameURL is an Objective C method. The equivalent Swift syntax would be
webView.mainFrameURL = "http://www.google.com"

Change UILabel from appDelegate

I want to do some stuff from the appDelegate in Xcode. One of these things are to change a UILabel.
ViewController *viewController = [[UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"id"];
viewController.label.text = #"heeej";
I was told this would do the trick. Doesn't work. Label doesn't change. Does anyone know what the problem is?
There are several problems:
Don't do anything in the AppDelegate except for loading the window an the initial view controllers (if needed).
You are instantiating a new view controller in the first line. I assume you already have a view controller and you want to change the label in that view controller. Than you need a reference to that view controller and use this reference to send messages to it.
The label should not be a property of the view controller. You should try to follow the design pattern Model-View-Controller or the pattern Model-View-ViewModel. Ask you preferred search engine what those are if you don't know.
id as an identifier for anything in Objective-C is a bad idea because this is used as an object type.
Edit: You don't need a reference to change a property in the view controller. Use notifications to update the label. The system sends a notification with the name UIApplicationWillEnterForgroundNotification' (see [here][1]). Add the view controller as an observer to the[NSNotificationCenter defaultCenter]` for this name and react on the notification. Read the Apple documentation if you don't know what I am talking about.

Pushing a navigation controller is not supported error message

I am working on an app where the user has the possibility to add products and those products are then displayed in a TableView. I created a TableViewController with static cells and two sections and I want to hook the cell in the second section with another TableViewController.
I dragged the TableViewController from the object library, embedded it in a navigation controller and made a push segue from the cell to the NavigationController but when I try to run the app I get the following error message in the output window:
2013-03-20 09:55:32.981 STAM[725:c07] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
First throw call stack:
(0x1d04012 0x11e8e7e 0x22a5b0 0x22a098 0x585da3 0x577ad9 0x577b54 0x1df899 0x1dfb3d 0xbe6e83 0x1cc3376 0x1cc2e06 0x1caaa82 0x1ca9f44 0x1ca9e1b 0x1f3c7e3 0x1f3c668 0x13065c 0x2a6d 0x2995)
libc++abi.dylib: terminate called throwing an exception
Here's a screenshot form my storyboard.
Thank you very much!
Granit
Your UINavigationController is at the wrong place. It should be before the UITableViewController.
You can select the UITableViewController from story board then from menu: Editor > Embed In > Navigation Controller.
You can get more info about the navigation stack from the reference guide.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

Issue feeding dynamically the uitableview in the masterview controller of a master/detail app

I am trying to feed the content of a masterview after creating a project based on the master/detail app template.
I have basically a model that content all my data which might change later on. I want to feed automatically the content of the tableview by providing the number of rows per section and number of sections that has this model.
I manage to do so by overriding the following 2 functions:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
I got a NSRangeException exception though if i didn't edit the storyboard for the Master View Controller - Master Scene such that it reflects a larger number of sections and rows in sections than my model has.
e.g: I left the storyboard for the Master Scene with 1 section and 1 row. If i return 2 in the numberOfRowsInSection function my program will crash at run time with this NSRangeExceptionError error:
2011-10-10 14:38:53.042 sample_project[3636:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x13bb052 0x154cd0a 0x13a7674 0x432805 0x24227a 0x1ed548 0x1ef722 0x9f7c7 0x9f2c1 0xa228c 0xa6783 0x51301 0x13bce72 0x1d6592d 0x1d6f827 0x1cf5fa7 0x1cf7ea6 0x1d8330c 0x114c6 0x11bd6 0x20743 0x211f8 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x112a7 0x12a9b 0x25e2 0x2555)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
Does anyone see a reason for this behavior? Am I missing something? Do I need to make some extra initialization that will set a default size for the tableview in the didLoad function of the controller?
I found out that the default table view Content attribute is set to static. You can change it to Dynamic Prototypes. You need to provide a identifier for the cell: I am not sure how this is used though. This solved the crash i was mentioning above.
More code of yours will actually help, but anyways,
There are some changes made in UIKit in IOS5, kindly check the following link, so that you dont conflict anywhere else in the code.
IOS 5 Release Notes
There is a change in the NSIndexPath too, check that particularly. As per apple docs,
The indexPathForRow:inSection:, section, and row methods of NSIndexPath now use NSInteger instead of NSUInteger, so that these types match with methods defined on UITableView.
If you find the answer, please share.

Resources