如何使用自定义返回类型创建方法?
我基本上想要返回“View Controller”,并进一步使用与界面构建器中的IBAction相同的方法并指向一个按钮...
我基本上想调用下面的方法或者创建一个可以使用按钮调用的自定义方法......它有办法吗?
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController labelContents]];
if(currentIndex == self.modelArray.count-1)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.labelContents = [self.modelArray objectAtIndex:currentIndex + 1];
return contentViewController;
}
答案 0 :(得分:2)
您可以创建方法并将其连接到按钮
·H
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController ;
-(IBAction)myMethod; //connect this to your button
的.m
-(IBAction)myMethod
{
//assuming you want you want to push to returned view controller
[self.navigationController pushViewController:[self pageViewController:viewController viewControllerAfterViewController:viewController2] animated:YES];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController labelContents]];
if(currentIndex == self.modelArray.count-1)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.labelContents = [self.modelArray objectAtIndex:currentIndex + 1];
return contentViewController;
}
答案 1 :(得分:-2)
IBAction仅用作提示,它不是“绑定”。这意味着您可以通过以下几种方式之一做您想做的事情:
编程。使用@selector(yourActionMethod :)
“技巧”xcode;首先将方法设置为IBAction,然后使用drag& amp; drop,然后更改方法的声明/实现。它会起作用。