I`m doing something wrong here but I can't figure out what it is .
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate> {
UIWindow *window;
UIScrollView *scrollView;
UIPageControl *pageControl;
NSMutableArray *viewControllers;
UIView *flipside;
// To be used when scrolls originate from the UIPageControl
BOOL pageControlUsed;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
#property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
#property (nonatomic, retain) IBOutlet UIView *flipside;
#property (nonatomic, retain) NSMutableArray *viewControllers;
- (IBAction)showInfo:(id)sender;
- (IBAction)changePage:(id)sender;
#end
AppDelegate.m
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
This is where I`m getting :
warning: class 'AppDelegate' does not implement the 'FlipsideViewControllerDelegate' protocol.
After line :
controller.delegate = self;
My FlipsideViewController.h looks like this :
#import <UIKit/UIKit.h>
#protocol FlipsideViewControllerDelegate;
#interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#en
Any help would be greatly appreciated :)
It's exactly what the error message says. AppDelegate just doesn't implement the protocol. In your header file, add FlipsideViewControllerDelegate between the brackets (i.e. <UIApplicationDelegate, UIScrollViewDelegate, FlipsideViewControllerDelegate>), and implement the -flipsideViewControllerDidFinish: method.
try adding FlipsideViewControllerDelegate to the appDelegate
#interface AppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate,FlipsideViewControllerDelegate> {
UIWindow *window;
UIScrollView *scrollView;
UIPageControl *pageControl;
NSMutableArray *viewControllers;
UIView *flipside;
// To be used when scrolls originate from the UIPageControl
BOOL pageControlUsed;
}
Related
//RootViewViewController.h
#import <UIKit/UIKit.h>
#import "SettingsViewController.h"
#import "OneSlotViewController.h"
#import "TwoSlotViewController.h"
#import "BingoSlotViewController.h"
#import "SettingsViewController.h"
#interface RootViewViewController : UIViewController{
IBOutlet UIButton *owaru;
OneSlotViewController *oneSlotViewController;
TwoSlotViewController *button2ViewController;
BingoSlotViewController *button3ViewController;
UIViewController *pushedController;
UIButton *hajimekara;
SettingsViewController *settingsVc;
}
#property (retain, nonatomic) UIButton *hajimekara;
#property (strong, nonatomic) IBOutlet UIButton *owaru;
#property (nonatomic, retain) OneSlotViewController *button1ViewController;
#property (nonatomic, retain) TwoSlotViewController *button2ViewController;
#property (nonatomic, retain) BingoSlotViewController *button3ViewController;
#property (nonatomic, retain) UIViewController *pushedController;
#property (nonatomic, retain) SettingsViewController *settingsVc;
//RootViewViewController.m
#synthesize button1ViewController;
#synthesize button2ViewController;
#synthesize button3ViewController;
#synthesize pushedController;
#synthesize settingsVc;
-(IBAction) startButtonPressed:(id) sender {
if (self.settingsVc.pushedController!=nil) {
NSLog(#"push");
[self presentViewController:self.settingsVc.pushedController animated:YES completion:NULL];
}
}
//SettingViewController.h
#import "OneSlotViewController.h"
#import "TwoSlotViewController.h"
#import "BingoSlotViewController.h"
#import "SettingsViewController.h"
#import "AGImagePickerController.h"
#class RootViewViewController;
#interface SettingsViewController : UIViewController<UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPopoverControllerDelegate,UIScrollViewDelegate>{
OneSlotViewController *oneSlotViewController;
TwoSlotViewController *button2ViewController;
BingoSlotViewController *button3ViewController;
UIViewController *pushedController;
RootViewViewController *mainVc;
UIImageView *lastPriceView;
CustomImagePicker *_imagePicker;
UINavigationController *navController;
}
#property (nonatomic, retain) UIPopoverController *popoverController;
#property (nonatomic, retain) OneSlotViewController *button1ViewController;
#property (nonatomic, retain) TwoSlotViewController *button2ViewController;
#property (nonatomic, retain) BingoSlotViewController *button3ViewController;
#property (nonatomic, retain) UIViewController *pushedController;
#property (nonatomic, retain) RootViewViewController *mainVc;
#property (strong, nonatomic) IBOutlet UIImageView *lastPriceView;
#property (nonatomic, retain) CustomImagePicker *imagePicker;
#property (nonatomic, retain) IBOutlet UINavigationController *navController;
//SettingViewController.m
-(IBAction) button1Pressed:(id)sender {
if (self.button1ViewController==nil) {
button1ViewController = [[OneSlotViewController alloc] init];
}
self.pushedController = button1ViewController;
}
-(IBAction) button2Pressed:(id)sender {
if (self.button2ViewController==nil) {
button2ViewController = [[TwoSlotViewController alloc] init];
}
self.pushedController = button2ViewController;
}
-(IBAction) button3Pressed:(id)sender {
if (self.button3ViewController==nil) {
button3ViewController = [[BingoSlotViewController alloc] init];
}
self.pushedController = button3ViewController;
}
I have already declare there instances un the two controllers.
Whenever a button is pressed in the SettingsViewController it will pass the ViewController to the MainViewController's startButton.
But I cant seem to make it work. Thanks for your help.
SettingsViewController.pushedController and MainViewController.pushedController are separate variables. Changing one will not effect the other.
You have two options. You either need to store the SettingsViewController in the MainViewController, or pass the MainViewController to SettingsViewController.
If MainViewController keeps a reference to the SettingsViewController, then you can:
-(IBAction) startButtonPressed:(id) sender {
if (self.settingsViewController.pushedController!=nil) {
NSLog(#"push");
[self presentViewController:self.settingsViewController.pushedController animated:YES completion:NULL];
}
}
If SettingsViewController is passed a reference to MainViewController, then you can:
-(IBAction) button1Pressed:(id)sender {
if (self.button1ViewController==nil) {
button1ViewController = [[ViewOneController alloc] init];
}
self.mainViewController.pushedController = button1ViewController;
}
-(IBAction) button2Pressed:(id)sender {
if (self.button2ViewController==nil) {
button2ViewController = [[ViewTwoController alloc] init];
}
self.mainViewController.pushedController = button2ViewController;
}
-(IBAction) button3Pressed:(id)sender {
if (self.button3ViewController==nil) {
button3ViewController = [[ViewThreeController alloc] init];
}
self.mainViewController.pushedController = button3ViewController;
}
Pick one of these things and you should be OK.
How can I subclass UITextView in UIActionSheet to overwrite canBeforeFirstResponder to disable copy, select, and select all in UITextView.
#import <UIKit/UIKit.h>
#class English;
#protocol EnglishDelegate
- (void)dismissViewDidFinish:(UIViewController *)viewController;
#end
#interface English: UIViewController <UITextViewDelegate, UIScrollViewDelegate>
{
id<EnglishDelegate> delegate;
UITextView *textView;
UINavigationBar *navBar;
UINavigationController *navigationController;
}
#property (nonatomic, retain) UITextView *textView;
#property (nonatomic, assign) UINavigationBar *navBar;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (nonatomic, assign) id<EnglishDelegate> delegate;
#property (nonatomic, retain) UIScrollView *scrollView;
-(void)dismissView:(id)sender;
#end
Anyone knows how to subclass it in h file.
Thanks for help.
You wouldn't subclass UITextView inside of another class; you would just plain subclass it in another file and override the canBecomeFirstResponder as so:
- (BOOL)canBecomeFirstResponder {
return NO;
}
I want to call a function in a viewController from my appDelegate but with the following code, it doesn't get called. What am I doing wrong?
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "DetailsToTransfer.h"
#class AccountDetailTransferViewController;
#interface AccountDetailTransferAppDelegate : NSObject <UIApplicationDelegate> {
DetailsToTransfer *objDetailsToTransfer;
}
#property (nonatomic, retain) DetailsToTransfer *objDetailsToTransfer;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet AccountDetailTransferViewController *viewController;
-(void)sendToTransferScreen:(NSArray *)detailsArray;
#end
AppDelegate.m:
....
-(void)sendToTransferScreen:(NSArray *)detailsArray {
[objDetailsToTransfer setLabels:detailsArray];
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[self.window addSubview:objDetailsToTransfer.view];
}
DetailsToTransfer.h:
#import <UIKit/UIKit.h>
#interface DetailsToTransfer : UIViewController {
NSArray *accountDetailsArray;
UILabel *nameLabel;
UILabel *accountLabel;
IBOutlet UIButton *btnTransfer;
IBOutlet UIButton *btnBack;
}
#property (nonatomic, retain) NSArray *accountDetailsArray;
#property (nonatomic, retain) IBOutlet UILabel *nameLabel;
#property (nonatomic, retain) IBOutlet UILabel *accountLabel;
-(IBAction)sendDetails;
-(IBAction)goBack;
-(void)setLabels:(NSArray *)array;
#end
DetailsToTransfer.m
....
-(void)setLabels:(NSArray *)array {
NSLog(#"Setting Labels");
self.nameLabel.text = [array objectAtIndex:0];
self.accountLabel.text = [array objectAtIndex:1];
}
....
I would like to add that all the properties have been synthesized and that I'm calling the method in the appDelegate properly (i checked using NSLogs)
In AppDelegate.m:
Looks as if you are calling a method on your object before the object has been created. Until you have alloc / init your object, there will be no labels to set text.
Try changing your method to this:
-(void)sendToTransferScreen:(NSArray *)detailsArray {
if (!objDetailsToTransfer) {
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[objDetailsToTransfer setLabels:detailsArray];
[self.window addSubview:objDetailsToTransfer.view];
}
}
The problem might be that you are trying to set the values on a object that hasn't been created yet. I also provided an if statement to prevent the object from being created multiple times.
I`m getting this annoying warning :
warning: 'AppDelegate' may not respond to '-presentModalViewController:animated:'
In this implementation file :
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
at the line :
self presentModalViewController:controller animated:YES];
and here is the header file :
#import <UIKit/UIKit.h>
#import "FlipsideViewController.h"
#interface AppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate, FlipsideViewControllerDelegate> {
UIWindow *window;
UIScrollView *scrollView;
UIPageControl *pageControl;
NSMutableArray *viewControllers;
UIView *flipside;
UIImageView *infoButton;
// To be used when scrolls originate from the UIPageControl
BOOL pageControlUsed;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
#property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
#property (nonatomic, retain) IBOutlet UIView *flipside;
#property (nonatomic, retain) IBOutlet UIImageView *infoButton;
#property (nonatomic, retain) NSMutableArray *viewControllers;
- (IBAction)showInfo:(id)sender;
- (IBAction)changePage:(id)sender;
#end
Obviously there is something I`m not getting, but I would appreciate if someone could help :)
You must persent modal view controllers from an instance of UIViewController (not your application delegate). If you check out the documentation on UIViewController, you can access a sample application using the modal presentation.
I am trying to load a UIView with multiple data. The problem is data is not displays in first load but loads it in subsequent clicks. Can you help me trace the problem.
FirstViewController.h
#import <UIKit/UIKit.h>
#class SecondViewController;
#interface FirstViewController : UIViewController {
IBOutlet SecondViewController *mySecondViewController;
IBOutlet UIImageView *myimage1;
IBOutlet UIImageView *myimage2;
IBOutlet UILabel *mylabel1;
IBOutlet UILabel *mylabel2;
}
#property (nonatomic, retain) IBOutlet SecondViewController *mySecondViewController;
#property (nonatomic, retain) IBOutlet UIImageView *myimage1;
#property (nonatomic, retain) IBOutlet UIImageView *myimage2;
#property (nonatomic, retain) IBOutlet UILabel *mylabel1;
#property (nonatomic, retain) IBOutlet UILabel *mylabel2;
- (IBAction)bringNextView:(id)sender;
- (IBAction)bringNextView2: (id)sender;
#end
FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
#implementation FirstViewController
#synthesize mySecondViewController,myimage1, myimage2, mylabel1, mylabel2;
- (IBAction)bringNextView:(id)sender {
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
}
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
#synthesize myimageview, name, statmsg
- (void)viewDidLoad {
[self setTitle:#"Details"];
[super viewDidLoad];
}
Properties are not coming for the first time. But are displays after returning from view and then loading view again.
I am loading SecondViewController from FirstViewController.
Hi I have solved this. Actually I was pushing my view controller after setting up the property and that caused this issue.
Instead of :
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
It should be :
[[self navigationController] pushViewController:mySecondViewController animated:YES];
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";