iOS开发--数据显示

作者: 一个有个性的女汉子 | 来源:发表于2016-12-23 19:07 被阅读45次

    今天通过后台传过来的数据,显示在了app上,具体代码如下:

    首先在model中:根据后台返回的数据打印出来,定义一个属性:

    @property(nonatomic,strong)NSArray*listData;

    然后在view.h中:

    - (void) fetchTimeLineListData;

    在view.m中实现:

    #pragma mark -请求list数据

    - (void)fetchTimeLineListData{

    TimeLineListAPI*api = [[TimeLineListAPIalloc]init];

    [apistartWithCompletionBlockWithSuccess:^(__kindofYTKBaseRequest*_Nonnullrequest) {

    TimeLineListModel*model = [TimeLineListModelyy_modelWithJSON:request.responseObject];

    self.successblock(model,0);

    NSLog(@"requestListData = %@",request.responseObject);

    }failure:^(__kindofYTKBaseRequest*_Nonnullrequest) {

    }];

    }

    在cell中重写model的set方法:

    - (void)setModel:(ListModel*)model{

    [supersetModel:model];

    self.tipLabel.text= model.title;

    [self.backImageViewsd_setImageWithURL:[NSURLURLWithString:model.cardImage]placeholderImage:[UIImageimageNamed:@"timeline_eventInvitation"]completed:^(UIImage*image,NSError*error,SDImageCacheTypecacheType,NSURL*imageURL) {

    }];

    }

    最后在controller中的

    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    中代码如下:

    if(indexPath.section==TIMELINE_TYPE_LIST){

    ListModel*model =_timeLineListModel.listData[indexPath.row];

    listTableViewCell*cell;

    NSString*cellIdentifier =cellIdentifierLisTry;

    cell = [tableViewdequeueReusableCellWithIdentifier:cellIdentifierforIndexPath:indexPath];

    cell.model= model;

    returncell;

    }

    returnnil;

    同时不要忘了写

    -(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {

    return200;

    }在这里,因为没有具体的数据,可以先给一个行高200.

    至此就实现了获取网络数据并显示的功能了,快操作试一下吧~

    相关文章

      网友评论

        本文标题:iOS开发--数据显示

        本文链接:https://www.haomeiwen.com/subject/qyokvttx.html