У меня есть прокрутка, в которой я создаю кнопки программно. На ощупь кнопка должна загрузить другой кончик. Проблема, на ощупь, я получаю
[ViewController buttonTest]: нераспознанный селектор отправлен на экземпляр
Позвольте мне пройти через код:
appdelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *viewController;
appdelegate.m
#import "ViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *view = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.viewController = [[UINavigationController alloc] initWithRootViewController:view];
self.window.rootViewController = self.viewController;
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[self.window makeKeyAndVisible];
return YES;
}
Viewcontroller.h
@class newView;
@interface ViewController : UIViewController{
UIScrollView * scrollView;
IBOutlet UIButton *btn;
}
- (IBAction)butttonTest:(id)sender;
@property (strong, nonatomic) newView *secondView;
и, наконец, ViewController.m
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.contentSize=CGSizeMake(320,960);
UIImageView *tempImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpeg"]];
UIImage * buttonImage = [UIImage imageNamed:@"contentlist_active.png"];
self.view=scrollView;
[scrollView addSubview:tempImageView2];
scrollView.userInteractionEnabled = YES;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(22, 100, 277, 32);
[btn setBackgroundImage:buttonImage forState:UIControlStateNormal];
[btn setTitle:@"hello world" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonTest:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:btn];
}
Чтобы загрузить вид, у меня есть код:
[btn addTarget:self action:@selector(buttonTest) forControlEvents:UIControlEventTouchUpInside];
Что я делаю не так?
О, да, вот метод для buttenPressed
- (IBAction)butttonTest:(id)sender {
self.secondView = [[newView alloc] initWithNibName:@"newView" bundle:nil];
[self.navigationController pushViewController:self.secondView animated:YES];
}