Je suis un nouveau dans iOS, et j'ai du mal à mettre en œuvre @protocol désolé si vous pensez que cela est une chose facile ..Fail dans l'attribution self.delegate il produire sélecteur non reconnu envoyé
i » J'ai été chercher autour de stackoverflow.com, les webs et aussi essayer oncle Google pendant un moment et j'ai décidé de demander ici ...
L'idée principale est d'appeler un MyViewController à partir de TopViewController et faire flip animation Je commence par créer le protocoles ..
// This is my Delegate header
// MyViewController.h
@protocol MyViewControllerlDelegate
- (void) myViewControllerDidFinish;
@end
@interface MyViewController : UIViewController
{
id <MyViewControllerlDelegate> delegate;
}
@property (nonatomic, assign) id <MyViewControllerlDelegate> delegate;
- (IBAction) done;
@end
et ci-dessous est la mise en œuvre:
// MyViewController.m
#import "MyViewController.h"
@implementation MyViewController
@synthesize delegate;
// Another Code above
- (IBAction)done
{
[self.delegate myViewControllerDidFinish];
}
// Another Code Below
@end
J'utilise ci-dessus objet à appeler d'une autre vue ci-dessous et ajouter la transition chiquenaude en elle:
// TopViewController.h
#import "MyViewController.h"
@class MapScrollView;
@interface TopViewController : UIViewController <UIScrollViewDelegate,MyViewControllerlDelegate>
{
UIScrollView *topScrollView;
UIButton *infoButton;
}
@end
TopViewController.h mise en œuvre // TopViewController. m
#import "TopViewController.h"
#import "CustomScrollView.h"
#import <QuartzCore/QuartzCore.h>
- (void)loadView
{
// Step 1: make the outer paging scroll view
CGRect topScrollViewRect = [[UIScreen mainScreen] bounds];
topScrollView = [[UIScrollView alloc] initWithFrame:topScrollViewRect];
topScrollView.pagingEnabled = YES;
topScrollView.backgroundColor = [UIColor blackColor];
topScrollView.showsVerticalScrollIndicator = NO;
topScrollView.showsHorizontalScrollIndicator = NO;
topScrollView.contentSize = CGSizeMake(topScrollViewRecte.size.width,
topScrollViewRecte.size.height);
topScrollView.delegate = self;
self.view = pagingScrollView;
CustomScrollView *sView = [[[MapScrollView alloc] init] autorelease];
sView.frame = [[UIScreen mainScreen] bounds];
[sView displayTiledMap];
[pagingScrollView addSubview:sView];
// add Info Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
[button addTarget:self action:@selector(infoIsTouch:) forControlEvents:UIControlEventTouchDown];
button.frame = CGRectMake(282.0, 440.0, 18.0, 19.0);
[self.view addSubview:button];
}
-(void)infoIsTouch:(id)sender
{
MyViewController *myView =
[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
myView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//
//Here where the code is crash
//
[myView setDelegate:self];
//
//Code from here to below is not run...
//
[self presentModalViewController:myView animated:YES];
[myView release];
}
- (void) myViewControllerDidFinish
{
[self dismissModalViewControllerAnimated:YES];
}
etc...
@end
Ci-dessous les produits de code suivant erreur du compilateur ..
2010-12-06 01:09:07.946 MyViewDelegatePractice[9473:207] -[TopViewController setDelegate:]: unrecognized selector sent to instance 0x5f30fb0
2010-12-06 01:09:07.949 MyViewDelegatePractice[9473:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TopViewController setDelegate:]: unrecognized selector sent to instance 0x5f30fb0'
*** Call stack at first throw:
(
// Cuts...
)
terminate called after throwing an instance of 'NSException'
Les erreurs est déclenché lorsque je presse infoButton qui appellent - (void) infoIsTouch: (id) méthode de l'expéditeur, puis arrêt à [myView setDelegate: auto] ligne .. Quelqu'un pourrait-il me donner un indice où est mes erreurs est ?
NOTE: Si vous dégoûter de mon anglais .. ne hésitez pas à commenter buter cela aussi .. mais avant cela .. Je suis désolé d'avoir mon mieux ..
'MyViewControllerlDelegate' et' FanglesMapSettingViewControllerDelegate', lequel est-il supposé implémenter? Je suis confus. – BoltClock
@ sam-ritchie - merci sam, c'est ma faute de frappe .. j'ai oublié de changer les variables .. désolé bout ce .. – FerryHtw
j'ai changé FanglesMapSettingViewControllerDelegate à MyViewControllerlDelegate mais toujours produire la même erreur .. – FerryHtw