BeeFramework-whatsbug代码学习【Lesson 1】

现在进行Bee的学习,随手做下笔记。

whatsbug作者博客http://www.whatsbug.com,在github中下载源码和sdk,安装sdk后新建一个空项目.运行源码中的WhatsBugs就是框架的示例代码。

这里我对Lession1的过程记录下来。

1.方便后面的练习分开,我建立如下路径.后续的练习复制01文件夹改为02就可以在原项目的基础上进行修改代码。

BeeFramework/01/BeeExp/BeeExp.xcodeproj

 

2.在iPhone/View创建分类的表格视图 CatelogBoard, 并修改代码

 

 

#import "Bee.h"
#import "Bee_UITableBoard.h"
#pragma mark -

@interface CatelogCell : BeeUIGridCell
{
    BeeUILabel* _title;
    BeeUILabel* _intro;
}

@end

@interface CatelogBoard : BeeUITableBoard
{
    NSMutableArray* _lessions;
}
@end
CatelogBoard.m
#import "CatelogBoard.h"
#import "Bee_Debug.h"
#import "Bee_Runtime.h"

#pragma mark -

@implementation CatelogCell

+ (CGSize)sizeInBound:(CGSize)bound forData:(NSObject *)data
{
    return CGSizeMake( bound.width,  60.0f);
}
-(void)layoutInBound:(CGSize)bound forCell:(BeeUIGridCell *)cell
{
    _title.frame = CGRectMake( 10.0f, 5.0f, cell.bounds.size.width - 20.0f, 30.0f);
    _intro.frame = CGRectMake( 10.0f, 32.0f, cell.bounds.size.width - 20.0f, 20.0f);
}
-(void)load
{
    [super load];
    
    _title = [[BeeUILabel alloc] init];
    _title.font = [UIFont boldSystemFontOfSize:18.0f];
    _title.textColor = [UIColor blackColor];
    _title.textAlignment = UITextAlignmentLeft;
    [self addSubview:_title];
    
    _intro = [[BeeUILabel alloc] init];
    _intro.font = [UIFont systemFontOfSize:14.0f];
    _intro.textColor = [UIColor blackColor];
    _intro.textAlignment = UITextAlignmentCenter;
    [self addSubview:_intro];
}

-(void)unload
{
    SAFE_RELEASE_SUBVIEW( _title );
    SAFE_RELEASE_SUBVIEW( _intro );
    //never to forget 
}
-(void)dataWillChange
{
    [super dataWillChange];
}
-(void)dataDidChanged
{
    [super dataDidChanged];
    
    if( self.cellData)
    {
        [_title setText:[(NSArray *)self.cellData objectAtIndex:1]];
        [_intro setText:[(NSArray *)self.cellData objectAtIndex:2]];
    }
    else
    {
        [_title setText:nil];
        [_intro setText:nil];
    }
}
@end

#pragma mark -

@implementation CatelogBoard

- (void)load
{
    [super load];
    
    _lessons = [[NSMutableArray alloc] init];
    
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson12Board", @"Lesson12 (New)", @"How to coding BeeUILayout", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson13Board", @"Lesson13 (New)", @"How to write BeeUILayout XML", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson14Board", @"Lesson14 (New)", @"How to use BeeUIQuery", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"DribbbleBoard", @"Dribbble.com (New)", @"Demo for dribbble.com", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"WebViewBoard", @"WebView Demo (New)", @"Demo for BeeUIWebView", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson1Board", @"Lesson 1", @"How to use BeeUIBoard", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson2Board", @"Lesson 2", @"How to use BeeUISignal", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson3Board", @"Lesson 3", @"How to use BeeUIStack", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson4Board", @"Lesson 4", @"How to use BeeUIStackGroup", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson5Board", @"Lesson 5", @"How to use BeeUITableBoard", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson6Board", @"Lesson 6", @"How to use BeeUIFlowBoard", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson7Board", @"Lesson 7 (New)", @"How to use Bee controls", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson8Board", @"Lesson 8 (New)", @"How to use BeeNetwork", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson9Board", @"Lesson 9 (New)", @"How to use BeeController", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson10Board", @"Lesson 10 (New)", @"How to use BeeModel & BeeCache", nil]];
    [_lessons addObject:[NSArray arrayWithObjects:@"Lesson11Board", @"Lesson 11 (New)", @"How to use BeeActiveRecord", nil]];

}
- (void)unload
{
    [_lessons removeAllObjects];
    [_lessons release];
    
    [super unload];
}

#pragma mark Signal

- (void)handleUISignal_BeeUIBoard:(BeeUISignal *)signal
{
    [super handleUISignal:signal];
    
    if ( [signal is:BeeUIBoard.CREATE_VIEWS] )
    {
        self.view.backgroundColor = [UIColor whiteColor];
        //self.view.hintString = @"CatalogBoard";

        [self showNavigationBarAnimated:NO];
        [self setTitleString:@"CatalogBoard"];

    }
    else if ( [signal is:BeeUIBoard.DELETE_VIEWS] )
    {
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize bound = CGSizeMake( self.view.bounds.size.width, 0.0f);
    return [CatelogCell sizeInBound:bound forData:nil].height;    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_lessons count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BeeUITableViewCell* cell = (BeeUITableViewCell *)[self dequeueWithContentClass:[CatelogCell class]];
    if( cell )
    {
        if( indexPath.row %2)
        {
            [cell.gridCell setBackgroundColor:[UIColor whiteColor]];
        }
        else
        {
            [cell.gridCell setBackgroundColor:[UIColor colorWithWhite:0.95f alpha:1.0]];
        }
    
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    
        cell.cellData = [_lessons objectAtIndex:indexPath.row];
        return cell;
    }
    return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];    
    //BeeLog(@"select");
    NSArray* data = [_lessons objectAtIndex:indexPath.row];
    BeeUIBoard* board = [[(BeeUIBoard *)[BeeRuntime allocByClassName:(NSString*)[data objectAtIndex:0]] init] autorelease];
    
    if( board )
    {
        [self.stack pushBoard:board animated:YES];
    }
}
@end

 

 

3.修改AppDelegate.h里面的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
            
    self.window.rootViewController = [BeeUIStackGroup stackGroupWithFirstStack:[BeeUIStack stackWithFirstBoard:[CatelogBoard board]]];//[CatalogBoard  board];这样写就没有导航栏

    [self.window makeKeyAndVisible];
    return YES;
}

 

4.新建 LessonBaseBoard ,并修改代码

 

  

#import "Bee.h"

#pragma mark -

@interface LessonBaseBoard : BeeUIBoard
{
    BeeUITextView *    _textView;
}
@end

  

LessonBaseBoard.m
#import "LessonBaseBoard.h"

#pragma mark -

@implementation LessonBaseBoard

DEF_SINGLETON( LessonBaseBoard );

- (void)handleUISignal:(BeeUISignal *)signal
{
    [super handleUISignal:signal];
    
    if ( [signal isKindOf:BeeUIBoard.SIGNAL] )
    {
        if ( [signal is:BeeUIBoard.CREATE_VIEWS] )
        {
            _textView = [[BeeUITextView alloc] initWithFrame:CGRectInset(self.viewBound, 5.0f, 5.0f)];
            _textView.font = [UIFont boldSystemFontOfSize:12.0f];
            _textView.textColor = [UIColor colorWithWhite:0.3f alpha:1.0f];
            _textView.editable = NO;
            [self.view addSubview:_textView];
        }
        else if ( [signal is:BeeUIBoard.DELETE_VIEWS] )
        {
            SAFE_RELEASE_SUBVIEW( _textView );
        }
    }
    
    [self updateText];
}

- (void)updateText
{
#if __BEE_DEVELOPMENT__
    NSMutableString * text = [NSMutableString string];
    BeeLog(@"Signals-Count:%d",self.signals.count);
    for ( NSUInteger i = 0; i < self.signals.count; ++i )
    {
        BeeUISignal * signal = [self.signals objectAtIndex:self.signals.count - i - 1];
        [text appendFormat:@"[%d] %@\n", self.signalSeq - i, signal.name];
    }
    
    _textView.text = text;
    _textView.scrollEnabled = YES;
    _textView.showsVerticalScrollIndicator = YES;
    [_textView flashScrollIndicators];
#endif    // #ifdef __BEE_DEVELOPMENT__
}

@end

 

 

5.新建 Lesson1Board 继承 LessonBaseBoard

#import "Bee.h"
#import "LessonBaseBoard.h"
#pragma mark -

@interface Lesson1Board : LessonBaseBoard
@end

 

Lesson1Board.m
#import "Lesson1Board.h"

#pragma mark -

@implementation Lesson1Board

// Other signal goes here
- (void)handleUISignal:(BeeUISignal *)signal
{
    [super handleUISignal:signal];
}

// BeeUIBoard signal goes here
- (void)handleUISignal_BeeUIBoard:(BeeUISignal *)signal
{
    [super handleUISignal:signal];
    
    if ( [signal is:BeeUIBoard.CREATE_VIEWS] )
    {
        // 界面创建
        
        [self setTitleString:@"Lesson 1"];
        [self showNavigationBarAnimated:NO];
    }
    else if ( [signal is:BeeUIBoard.DELETE_VIEWS] )
    {
        // 界面删除
    }
    else if ( [signal is:BeeUIBoard.LAYOUT_VIEWS] )
    {
        // 界面重新布局
    }
    else if ( [signal is:BeeUIBoard.LOAD_DATAS] )
    {
        // 数据加载
    }
    else if ( [signal is:BeeUIBoard.FREE_DATAS] )
    {
        // 数据释放
    }
    else if ( [signal is:BeeUIBoard.WILL_APPEAR] )
    {
        // 将要显示
    }
    else if ( [signal is:BeeUIBoard.DID_APPEAR] )
    {
        // 已经显示
    }
    else if ( [signal is:BeeUIBoard.WILL_DISAPPEAR] )
    {
        // 将要隐藏
    }
    else if ( [signal is:BeeUIBoard.DID_DISAPPEAR] )
    {
        // 已经隐藏
    }
}


@end

 

.后续的练习可以根据这个项目为原型进行修,bee的文档暂时比较少,可以根据whatsbug进行学习

 

 

 

 

 

posted @ 2013-04-25 16:49  yxieguodong  阅读(972)  评论(0编辑  收藏  举报