In this tutorial,是否可以将按钮仅添加到第一个视图,即索引== 0? 如果是,如何?将按钮添加到使用uipageviewcontroller创建的视图
-1
A
回答
1
在页面内容视图控制器中,有一个名为pageIndex(NSUInteger)的属性。
页面浏览控制器在制作新内容页面时设置此属性。
假设你有两个内容页面,那么第一个页面的pageIndex属性为0,下一个将为1. 所有你需要做的就是检查pageIndex是否等于0(表示它是第一个内容页面)并实现该页面的按钮。
假设你知道如何使一个按钮,页面内容视图控制器把这个在你目前的viewDidLoad代替:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if(self.indexNumber == 0) {
// code to make your button.
}
}
1
在MainViewController.m文件
- (void)viewDidLoad
{
//PageView Controller Code
UIPageViewController *pageVcObject = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
pageVcObject.dataSource = self;
pageVcObject.delegate = self;
CGRect frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-100);
// [pageVcObject.view setFrame:self.view.bounds];
[pageVcObject.view setBackgroundColor:[UIColor clearColor]];
[pageVcObject.view setFrame:frame];
ChildVcForPageViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[pageVcObject setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:pageVcObject
];
[[self view] addSubview:[pageVcObject view]];
[pageVcObject didMoveToParentViewController:self];
}
的#pragma标记 - UIPageViewControllerDataSource方法
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(ChildVcForPageViewController *)viewController
{
NSInteger index = [viewController index];
pageControl.currentPage = index;
index++;
if (index == imagesArray.count)
return nil;
else
{
return [self viewControllerAtIndex:index];
}
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(ChildVcForPageViewController *)viewController
{
NSInteger index = [viewController index];
pageControl.currentPage = index;
if (index == 0) return nil;
index--;
return [self viewControllerAtIndex:index];
}
- (ChildVcForPageViewController *)viewControllerAtIndex:(NSUInteger)indexValue
{
ChildVcForPageViewController *childViewController = [[ChildVcForPageViewController alloc] init];
childViewController.index = indexValue;
return childViewController;
}
在ChildVcForPageViewController.h声明类似下面
@property (assign, nonatomic) NSInteger index;
然后添加在ChildVcForPageViewController.m代码文件
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if(self.index == 0) {
// code to make your button.
UIButton *buttonz = [UIButton buttonWithType:UIButtonTypeCustom];
buttonz.frame = CGRectMake(160, 0, 160, 30);
[buttonz setTitle:@"Charge" forState:UIControlStateNormal];
[buttonz addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[backImageView addSubview:buttonz];
}
}
相关问题
- 1. 添加在App.xaml中创建的按钮到一个视图
- 2. 试图按钮添加到UIPageViewController,但按钮不会显示出来,即使他们在视图层次
- 3. 使用视图添加按钮布局
- 4. 创建一个按钮并以编程方式将其添加到视图中
- 5. 将分页添加到uipageviewcontroller
- 6. 使用按钮添加新行到asp .net网格视图使用按钮
- 7. 将图像添加到其他视图中的按钮
- 8. 将图像添加到列表视图中的按钮
- 9. 将附件视图按钮添加到MKMapView调用注释?
- 10. 将使用添加到主页按钮
- 11. 将事件监听器添加到动态创建的按钮
- 12. 将按钮添加到片段中的另一个视图
- 13. 将按钮阵列添加到特定的子视图
- 14. 将按钮添加到列表视图中的每一行
- 15. 将按钮添加到Android中的自定义视图中
- 16. 将事件添加到滚动视图中的按钮阵列
- 17. 将图标添加到按钮
- 18. 将图片添加到按钮
- 19. 将按钮添加到图表 - svg
- 20. 不能将图像添加到按钮
- 21. 将图标添加到jQuery按钮
- 22. 使用按钮添加布局到列表视图
- 23. 如何通过使用Swift单击按钮将项目添加到表格视图时获取创建日期?
- 24. 将按钮添加到使用java图形的contentPane
- 25. 添加图像到按钮
- 26. 将按钮添加到BrowseFragment
- 27. 将按钮添加到ListActivity
- 28. 将按钮添加到QTableview
- 29. 将按钮添加到infoWindow
- 30. 将按钮添加到UIScrollview
我如何做到这一点的财产? – 2014-12-03 11:59:04
为你编辑答案,这是否足够清楚? – 2014-12-03 12:08:29
与示例相关的任何示例代码? – 2014-12-03 12:11:51