Fer*_*Htw 4 delegates protocols objective-c flip ios
我是一个新的iOS和我在落实麻烦@protocol很抱歉,如果你认为这是一件容易的事情..
我一直在四处寻找stackoverflow.com,该网也尝试叔叔谷歌了一会儿,我决定问这里...
其主要思想是调用从TopViewController一个MyViewController,做翻转动画我创建协议开始..
// 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
Run Code Online (Sandbox Code Playgroud)
以下是实施:
// MyViewController.m
#import "MyViewController.h"
@implementation MyViewController
@synthesize delegate;
// Another Code above
- (IBAction)done
{
[self.delegate myViewControllerDidFinish];
}
// Another Code Below
@end
Run Code Online (Sandbox Code Playgroud)
我使用上面的对象从下面的另一个视图调用并在其中添加翻转过渡:
// TopViewController.h
#import "MyViewController.h"
@class MapScrollView;
@interface TopViewController : UIViewController <UIScrollViewDelegate,MyViewControllerlDelegate>
{
UIScrollView *topScrollView;
UIButton *infoButton;
}
@end
Run Code Online (Sandbox Code Playgroud)
TopViewController.h实现//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
Run Code Online (Sandbox Code Playgroud)
下面的代码产生以下编译错误..
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'
Run Code Online (Sandbox Code Playgroud)
当我按下infoButton其称之为引发这些错误 - (空)infoIsTouch:(ID)发送方法,然后停在[MyView的setDelegate:自我]行..任何人都可以给我一个提示哪里是我的错误是什么?
注意:如果你厌恶我的英语..随意评论也可以..但在那之前..我很抱歉我尽我所能..
| 归档时间: |
|
| 查看次数: |
11558 次 |
| 最近记录: |