merge iAD within another view / definition - ios

i am having trouble merging iAD into my current code/definition. i already have code set for a card scroll view style display and wanted to add iAD to the same view controller:
how can i do that without getting the errors i am getting?
this is the code for card scroll view in view controller.h
#interface ViewController1 : UIViewController <CardScrollViewDelegate>
#end
this is my code for iAD for view controller.h but should be merged with the above otherwise i get another error saying duplicate definition:
#interface ViewController1 : UIViewController <ADBannerViewDelegate> {
SLComposeViewController *mySLComposeSheet;
}
#property (weak, nonatomic) IBOutlet ADBannerView *banner1;
The view controller name / custom class im trying to add them both to is ViewController1
UPDATE:
its much simpler than i thought, just add a comma (FOR THOSE WHO ARE CURIOUS LIKE I WAS)
#interface ViewController1 : UIViewController <CardScrollViewDelegate, ADBannerViewDelegate> {
}
#property (weak, nonatomic) IBOutlet ADBannerView *banner1;
#end

Your code and/or question is ambiguious. I see 3 view controllers and 2 delegates. Eitherway...which viewcontroller are you trying to add it to? Whichever one it is. Inside the implementation file should be the following:
Remember to import iAd and your code should look like this:
#import <iAd/iAd.h>;
#interface ViewController1 : UIViewController <ADBannerViewDelegate>
{
ADBannerView *banner1;
BOOL bannerIsVisible;
}
#property (nonatomic,assign) BOOL bannerIsVisible;
Then, in viewDidLoad you can load it in a frame etc...

Related

Outlet collection with NSArray to singleton

I have a sequencer with each track that has buttons as an outlet collection. The code all works fine in it's own view controller however I want to transfer all the methods to a singleton so that I can control the playback from other views.
for instance I have
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *trackOneOutletCollection;
However I have methods which act on the alpha and tags of each button; the methods contain these vales which I don't know how to access from the singleton. I thought the singleton was where I store all the data and then call it from the class file view controller?
You can use Inheritance concept to achieve this functionality.you need to create one ParentViewController that hold IBOutletCollection property. and rest of all View Controller is child of ParentViewController. then you can access IBOutletCollection in other view ontroller. like this way.
ParentViewController:-
#interface ParentViewController : UIViewController
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *trackOneOutletCollection;
#end
ChildViewController;-
#interface YourViewController : ParentViewController
#end
.m file
#implementation YourViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"trackOneOutletCollection = %#"self.trackOneOutletCollection);
}
#end

How to change page with UISlider from an UIView

To summarize my app, it's like an iBook : I have multiple pages filled in with an xml file (text and image).
Like in the iBook app, I want to use a UISlider to select and change page.
I use a UIViewController (appViewController) as contener of the different UIViews (contentViewController)
header of AppViewController :
#import <UIKit/UIKit.h>
#import "contentViewController.h"
#interface AppViewController : UIViewController <UIPageViewControllerDataSource>
{
UIPageViewController *pageController;
NSArray *pageContent;
NSDictionary *pageFields;
}
in AppViewController.m, I have :
// Create a new view controller and pass suitable data.
contentViewController *dataViewController = [[contentViewController alloc]initWithNibName:#"contentViewController" bundle:nil];
The header of the contentViewController is :
#import <UIKit/UIKit.h>
#class DCIEquipment;
#interface contentViewController : UIViewController
#property (nonatomic,strong) DCIEquipment *eqt;
#property (assign, nonatomic) NSUInteger pageIndex;
#property (assign, nonatomic) NSUInteger pageNumber;
#property (strong, nonatomic) IBOutlet UISlider *pageSlider;
#end
Because in iBook, the slider seems to follow the curling movement of the page, I put my UISlider on the contentViewController. Everything works good with the UISlider but I don't how know to do to informe the UIViewController to change the page (I assumed that the code of changing the page has to be done in this controller).
Please tell me if you need some more code. I hope that explainations are clear. I juste want to know where to put the UISlider (which view) and how to send value to the pageViewController.
Thank you in advance.
Raphael
Use the protocols. There are lots of examples. And you are using at least one of them (UIPageViewControllerDataSource).
Just create one for your contentViewController (in it's header file)
#class ContentViewController; // this is fast-forward declaration
#protocol ContentViewControllerDelegate
- (void)contentViewController:(ContentViewController *)controller didChangePage:(NSUInteger)pageIndex;
#end
#interface ContentViewController : UIViewController
// ...
#property (weak,nonatomic) id<ContentViewControllerDelegate> delegate; // don't forget to set the value with your appViewController
// ...
#end
In your ContentViewController-implementation file in some method just call the delegate method
if (self.delegate && [self.delegate respondsToSelector:#selector(contentViewController:didChangePage:)])
[self.delegate contentViewController:self didChangePage:newIndex];
And don't forget to implement this method in appViewController class.

Referencing outlet not showing up in xcode 6

I am trying to write my first hello world in xcode. I have two labels and two buttons in my view, and my AppDelegate.h file is like this:
#interface QuizAppDelegate : NSObject <UIApplicationDelegate>
{
int currentQuestionIndex;
// The model objects
NSMutableArray *questions;
NSMutableArray *answers;
// The view objects
IBOutlet UILabel *questionField;
IBOutlet UILabel *answerField;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
- (IBAction)showQuestion:(id)sender;
- (IBAction)showAnswer:(id)sender;
#end
Now i am trying to add reference to my label. I go to LaunchScreen.xib and right click on the label. According to the tutorial, i have to see "answerField" and "questionField" under the "Outlets" tab, but nothing shows up. Can anyone tell me why this can be happening?
Thanks
A few things:
1) That code should really be in a view controller and not the application delegate
2) You probably should be looking in the Main.storyboard file and not LaunchScreen.xib
3) Make sure that File's Owner is set to the correct view controller on Main.storyboard after you move that code into a view controller.

iOS MVC implementation with custom views

When the views are simple, their IBActions and IBoutlets are in viewcontroller, viewcontrollers assigns respective models to be loaded and viewcontroller get notified when models are prepared.
As My project contains lot of custom views for each viewcontroller, I want to implement actions in custom view itself and set data from controller (ViewController).
I should be able to use the same controllers and models for both iPhone and iPad where only UI changes.
I am concerned about how to pass data from view to viewcontroller and displaying data back on view when model changes?
Can anyone please suggest me to pass data between views <---> viewcontroller (controller) <---> model?
To do this I use Delegate design-pattern. It looks like this :
MyView.h
#protocol MyViewDelegate <NSObject>
- (void)customViewDidSomething;
#end
#interface MyView : UIView
#property (nonatomic, assign) id<MyViewDelegate> delegate
#end
MyView.m
- (void)userDidSomething {
[_delegate customViewDidSomething];
}
MyViewController.h
#import "MyView.h"
// ViewController has to implement the protocol
#interface MyViewController <MyViewDelegate>
#property (nonatomic, retain) IBOutlet MyView myView;
MyViewController.m
- (void)viewDidLoad { // Set the delegate somewhere
_myView.delegate = self
}
- (void)customViewDidSomething {
// Ok VC is aware that something happened
// Do something (tell subview to do something ?)
}
Instead of using different custom views, try using a UIViewController and then use the viewcontroller's view to display your UI. Also, this will also ensure that you will be able to communicate between the views and controller efficiently without confusion.

Segmented Control- Change label text in another view

I have 2 views 1) ViewController and 2)ViewController2.
In the first view controller I have some lablels that when I run the segment controller the names change. All I want to do is, in (Viewcontroller2) where I have a label, I want it to be able to change the text as well based on the segmented controller being 0 or 1. Here is what I have.
// ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UISegmentedControl *Lang;
IBOutlet UIButton *Run;
IBOutlet UILabel *bet;
}
-(IBAction)ChangeLang:(id)sender;
#end
Then in the m file i have the following to change the data
// ViewController.m
#import "ViewController.h"
#import "ViewController2.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)ChangeLang :(id)sender {
if (Lang.selectedSegmentIndex==0)
{
bet.text=#"Apple";
Run.titleLabel.text=#"Banana";
//not sure here what code to put in order to make the label in viewcontroller2 change.
}
if (Lang.selectedSegmentIndex==1) {
bet.text=#"ORANGES";
Run.titleLabel.text=#"FRUITS";
//not sure here what code to put in order to make the label in viewcontroller2 change.
}
}
This runs fine... heres what I have in VIEWController 2
// Viewcontroller2.h
#import <UIKit/UIKit.h>
#interface ViewController2 : UIViewController
IBOutlet UILabel *Nextword;
#end
In the M controller i just have this
#import "ViewController2.h"
#import "ViewController.h"
#interface ViewController2 ()
#end
How would I, when I run the segmented controller, make the uilabel text change in the ViewController2? Can anyone help? I dont want the screen to go to viewcontroller automatically, I was able to do that. I want the text to change, and then when i swipe to go there, i want the text in Viewcontroller2 to be according to the if statement based on the segmented controller.
Thank you
You need to have an access to instance of ViewController2 from ViewController.
Use this code inside your ViewController.h file:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UISegmentedControl *Lang;
IBOutlet UIButton *Run;
IBOutlet UILabel *bet;
ViewConstroller2 * VC2;
}
-(IBAction)ChangeLang:(id)sender;
#end
When you're creating instance of ViewController2 store it in VC2 variable.
Then use this code as your UISegmentedControl change event:
-(IBAction)ChangeLang:(id)sender {
if (Lang.selectedSegmentIndex==0)
{
bet.text=#"Apple";
Run.titleLabel.text=#"Banana";
VC2.Nextword= "YOUR_WORD";
}
if (Lang.selectedSegmentIndex==1) {
bet.text=#"ORANGES";
Run.titleLabel.text=#"FRUITS";
VC2.Nextword= "YOUR_WORD";
}
}

Resources