iOS开发--数据显示

今天通过后台传过来的数据,显示在了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.

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容