#import "ViewController.h"
#import "CGTabbar.h"
#import "QHCListView.h"
#import "QHJavaListView.h"
#import "QHOCListView.h"
@interface ViewController ()<CGTabbarDelegate>
@property(nonatomic,strong)NSArray *books;
@property(nonatomic,weak)QHOCListView *ocListView;
@property(nonatomic,weak)QHJavaListView *javaListView;
@property(nonatomic,weak)QHCListView *cListView;
@end
@implementation ViewController
-(QHOCListView *)ocListView
{
if (_ocListView == nil) {
QHOCListView *ocListView = [QHOCListView ocListView];
[self.view addSubview:ocListView];
_ocListView = ocListView;
}
return _ocListView;
}
-(QHJavaListView *)javaListView
{
if (_javaListView == nil) {
QHJavaListView *javaListView = [QHJavaListView javaListView];
[self.view addSubview:javaListView];
_javaListView = javaListView;
NSLog(@"+++++++++++");
}
return _javaListView;
}
-(QHCListView *)cListView
{
if (_cListView == nil) {
QHCListView *cListView = [QHCListView cListView]
;
[self.view addSubview:cListView];
_cListView = cListView;
}
return _cListView;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:@"books.plist" ofType:nil];
_books = [NSArray arrayWithContentsOfFile:path];
//NSLog(@"%@",_books);
CGTabbar *tabbar = [CGTabbar tabbar];
[self.view addSubview:tabbar];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
[self configButton:btn1 andTitile:@"OC" andImageName:@"upomp_button_keyboard3" andSelectedImageName:@"upomp_button_keyboard3_highlighted"];
[self configButton:btn2 andTitile:@"Java" andImageName:@"upomp_button_keyboard3" andSelectedImageName:@"upomp_button_keyboard3_highlighted"];
[self configButton:btn3 andTitile:@"C" andImageName:@"upomp_button_keyboard3" andSelectedImageName:@"upomp_button_keyboard3_highlighted"];
tabbar.delegate = self;
tabbar.items = @[btn1,btn2,btn3];
NSLog(@"%@",_books);
// Do any additional setup after loading the view, typically from a nib.
}
-(void)configButton:(UIButton *)btn andTitile:(NSString *)title andImageName:(NSString *)imageName andSelectedImageName:(NSString *)selectedImageName
{
[btn setTitle:title forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
}
-(void)tabbarItemSelected:(CGTabbar *)tabbar andItem:(UIButton *)item andIndex:(NSInteger)index
{
if (index==0) {
[self.view bringSubviewToFront:self.ocListView];
NSLog(@"--------------");
}
else if(index ==1)
{
[self.view bringSubviewToFront:self.javaListView];
}
else if(index ==2)
{
[self.view bringSubviewToFront:self.cListView];
}
[self.view bringSubviewToFront:tabbar];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "ViewController.h"
#import "CGTabbar.h"
#i