model框架

启动的时候状态栏颜色是绿色的,,,是info里面的statusbar染色引起的。。。  df  领导:

==================另外demo也可以写多余的属性,读取的时候只会读名字一样的,只用于相似的几个页面。。。。。。。。。===========

 

--------上啦刷新,下拉加载更多看 MessageViewController 就行了。。。。。。

 

///下面两句的父类的两个属性。。。。。

@property (strong, nonatomic) NSMutableDictionary *myBaseDict;  ///请求url的时候传入的参数。。

@property (strong, nonatomic) NSMutableArray *applications;     ///返回的model的上一层。。

 

///一:Demo_Model

 

#import "ITTBaseModelObject.h"

@interface LiShiModel : ITTBaseModelObject

@property (nonatomic, strong) NSString *visitid;

@property (nonatomic, strong) NSString *company;

@property (nonatomic, strong) NSMutableArray *collaborative;

@end

 

#import "LiShiModel.h"

@implementation LiShiModel

- (NSDictionary*)attributeMapDictionary

{

    return @{@"visitid":@"visitid", @"company":@"company", @"collaborative":@"collaborative"};    //后面的是网络的字段,前面的是属性名。

}

@end

 

///二:Demo_Request  --------下面是post方法。。。。===get请求跟这一样,=- (ITTRequestMethod)getRequestMethod 改成get就行了。传参还是用字典。===========

 

#import "ITTAFNBaseDataRequest.h"

@interface LiShiRequest : ITTAFNBaseDataRequest

@end

 

 

//http://192.168.1.8/zhongwei_api/index.php?m=ivisithistory&userid=3

#import "LiShiRequest.h"

#import "LiShiModel.h"

@implementation LiShiRequest

 

- (ITTRequestMethod)getRequestMethod

{

    return ITTRequestMethodPost;

}

 

- (NSString*)getRequestUrl

{

    return [NSString stringWithFormat:@"%@%@", [self getRequestHost], @"/zhongwei_api/index.php?m=ivisithistory"];

}

 

- (void)processResult

{

    ///不用继承父类,继承父类没有用的,还会起反作用。

    NSArray *appdicArray = self.handleredResult[@"result"];

    self.handleredResult2 = self.handleredResult;

    self.result = [[ITTRequestResult alloc] initWithCode:@"0" withMessage:@""];

    if (appdicArray && [appdicArray count]) {

        NSMutableArray *applications = [NSMutableArray array];

        for (NSDictionary *appdic in appdicArray) {

            //            for (NSDictionary *appdic2 in [appdic objectForKey:@"info"]) {

            LiShiModel *application = [[LiShiModel alloc] initWithDataDic:appdic];

            [applications addObject:application];

            //                [applications addObject:appdic2];

            //            }

        }

        self.handleredResult = [NSMutableDictionary dictionaryWithObjectsAndKeys:applications, KEY_APPLICATION, nil];

    }

}

@end

 

///三:在viewcontroller里面用的时候。

@interface LIShiViewController : BaseViewController<UITableViewDataSource,UITableViewDelegate>

 

@property (strong, nonatomic) UITableView *myTableV;

@property (strong, nonatomic) NSMutableArray *myDataArray;

@property (strong, nonatomic)LiShiModel *lishiModel;

@end

 

 

///或者传一个字典,父类有一个字典。已经初始化了。并且 self.applications 是父类初始化好的一个数组。用来放model

[LiShiRequest requestWithParameters:@{@"userid":[kUserDefault objectForKey:@"userid"]}

withIndicatorView:self.view

withCancelSubject:APPLICATION_LIST_REQUEST_CANCEL_SUBJECT

onRequestStart:^(ITTBaseDataRequest *request) {

}

onRequestFinished:^(ITTBaseDataRequest *request) {

    if ([request isSuccess]) {

        //成功的时候执行下面的方法。

        if ([[request.handleredResult2 objectForKey:@"code"] intValue]==10) {

            

            ///如果不是表格形式的,可以用下句弹出请求成功的提示。

            //[self.view.window showHUDWithText:[request.handleredResult objectForKey:@"msg"] Type:ShowPhotoYes Enabled:YES];

            

            

            self.applications = request.handleredResult[KEY_APPLICATION];

            ///tableview 里面 一一赋值给model就行了。。。。

            [self.myTableV reloadData];

        }else{

            [ViewControllerFactory showMessageAlert:[request.handleredResult objectForKey:@"msg"]];

        }

    }else{

        [ViewControllerFactory showMessageAlert:[request.handleredResult objectForKey:@"msg"]];

    }

}

onRequestCanceled:^(ITTBaseDataRequest *request) {

    

    

}

onRequestFailed:^(ITTBaseDataRequest *request) {

    

    [ViewControllerFactory showMessageAlert:@"请求失败!"];

    

}];

 

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2005382
今日推荐