我是IOS的新手并创建了一款应用。我正在使用CapsPageMenu iOS objective-c库。我在Tap上看到了这一点,例如:如果我有Tab1,Tab2,Tab3和Tab4,我当前在Tab1上,那么当我点击Tab4时,我看到Tab2的API也被调用了。这很可能是因为可以看到Tab2视图水平滚动一秒..但是我需要在加载时从每个选项卡上的Web服务获取数据。因此,这会导致不必要的网络呼叫。
如何确保仅在实际加载该选项卡时对选项卡执行Web服务调用,而不是滚动过去?
父ViewController CapsPageMenu
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Point History";
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[ApplicationDesignClass sharedInstance].appLayoutDesign.appHeader._headerLabel._textColor}];
ViewController *controller1 = [[AllViewController alloc]initWithNibName:@"AllViewController" bundle:nil];
controller1.title = @"ALL";
controller1.historyType = HistoryTypeAll;
ViewController *controller2 = [[AllViewController alloc]initWithNibName:@"AllViewController" bundle:nil];
controller2.title = @"ADDED";
controller2.historyType = HistoryTypeAdded;
ViewController *controller3 = [[AllViewController alloc]initWithNibName:@"AllViewController" bundle:nil];
controller3.title = @"USED";
controller3.historyType = HistoryTypeUsed;
ViewController *controller4 = [[AllViewController alloc]initWithNibName:@"AllViewController" bundle:nil];
controller4.title = @"UNUSED";
controller4.historyType = HistoryTypeUnused;
NSArray *controllerArray = @[controller1, controller2, controller3, controller4];
NSDictionary *parameters = @{
CAPSPageMenuOptionScrollMenuBackgroundColor: [UIColor blackColor],
CAPSPageMenuOptionUnselectedMenuItemLabelColor: [UIColor whiteColor],
CAPSPageMenuOptionSelectedMenuItemLabelColor: [UIColor lightgraycolor],
CAPSPageMenuOptionViewBackgroundColor: [UIColor colorWithRed:20.0/255.0 green:20.0/255.0 blue:20.0/255.0 alpha:1.0],
CAPSPageMenuOptionSelectionIndicatorColor: [UIColor whiteColor],
CAPSPageMenuOptionBottomMenuHairlineColor: [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:1.0],
CAPSPageMenuOptionMenuItemFont: [UIFont fontWithName:@"HelveticaNeue" size:13.0],
CAPSPageMenuOptionMenuHeight: @(40.0),
CAPSPageMenuOptionMenuItemWidth: @(70.0),
CAPSPageMenuOptionCenterMenuItems: @(NO)
};
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height) options:parameters];
[self.view addSubview:_pageMenu.view];
}
Child ViewController
注意: - 例如:如果我有AllTab,AddedTab,UsedTab和UnusedTab,我目前在AllTab上,那么当我点击UnusedTab时,我看到AddedTab数据显示但我想要UnusedTab数据显示
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, HistoryType){
HistoryTypeAll,
HistoryTypeAdded,
HistoryTypeUsed,
HistoryTypeUnused
};
@interface ViewController : UIViewController
@property (nonatomic, assign) HistoryType historyType;
@end