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