标签:bee framework ios 开发框架
这一次分享一下BeeMessage, BeeModel, 和BeeUISignal。这三个东东就是Controller, Model, 和Event的主要实现。您也可以到Bee的/documents/developer_manual.pdf中查看详细的开发手册,希望您看了这篇文章能对这几个组件理解更深,适合干什么,从而更得心应手得使用。本文试图解答几个问题:
-(void) getNewsList {
BeeMesage * api = [API_NEWS_LIST api];//加入Http参数
api.INPUT( @"uid", [NSString stringWithFormat:@"%d", _uid]);<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">
</p> api.whenUpdate = ^
{
if ( api.sending )
{
//处理发送
}
else if(api.succeed)
{ //发送成功,获得BeeMessage解析好的数据
[self.news addObjectsFromArray:api.resp.news];
}
else if ( api.failed )
{ //处理失败
}
else if ( api.cancelled )
{ //处理取消
}
};
[api send];}
- (void)routine
{
if ( self.sending )
{
NSString * requestURI = [[[ServerConfig sharedInstance] url] stringByAppendingString:api_news_list];
self.HTTP_GET( requestURI );
}
else if ( self.succeed )
{
NSError* error; //通过XML解析回文
CXMLDocument * document = [[CXMLDocument alloc] initWithXMLString:self.responseString options:NSUTF8StringEncoding error:&error];
NSArray* newslist = [document nodesForXPath:@"oschina/newslist/news" error:&error];
for ( CXMLElement* newsXML in newslist )
{
if(newsXML == nil) continue;
NEWS* news = [NEWS createByXML:newsXML];
[self.resp.news addObject:news];
}
if ( nil == self.resp || NO == [self.resp validate] )
{
self.failed = YES;
return;
}
}
else if ( self.failed )
{
}
else if ( self.cancelled )
{
}
}
@end- (void)firstPage
{
_pages = 0;
[API_POST_LIST cancel];
API_POST_LIST *api = [API_POST_LIST api];
//每页20个
api.INPUT( @"pageIndex", @"0" );
api.INPUT( @"pageSize", @"20" );
api.whenUpdate = ^
{
@normalize( api );
if ( api.sending )
{
[self sendUISignal:self.RELOADING];
}
else if ( api.succeed )
{
//第一页拉取成功
[self.posts removeAllObjects];
[self.posts addObjectsFromArray:api.resp.posts];
self.loaded = YES;
self.pages = 1;
[self sendUISignal:self.RELOADED];
}
else if ( api.failed )
{
[self sendUISignal:self.RELOADED];
}
};
[api send];
}
- (void)nextPage
{
[API_POST_LIST cancel];
API_POST_LIST *api = [API_POST_LIST api];
int curBegin = self.pages * 20;
int curEnd = curBegin + 20;
api.INPUT( @"pageIndex", [NSString stringWithFormat:@"%d", curBegin]);
api.INPUT( @"pageSize", [NSString stringWithFormat:@"%d", curEnd] );
api.whenUpdate = ^
{
@normalize( api );
if ( api.sending )
{
[self sendUISignal:self.RELOADING];
}
else if ( api.succeed )
{ //处理下一页
if( _pages == 0)
{
[self.posts removeAllObjects];
}
[self.posts addObjectsFromArray:api.resp.posts];
self.loaded = YES;
self.pages = self.pages + 1;
[self sendUISignal:self.RELOADED];
}
else if ( api.failed )
{
[self sendUISignal:self.FAILED];
}
else if ( api.cancelled )
{
[self sendUISignal:self.CANCELLED];
}
};
[api send];
}
iOS快速开发框架Bee-Framework应用和解析(三) --- Message, Model, Signal
标签:bee framework ios 开发框架
原文地址:http://blog.csdn.net/u011173875/article/details/43734831