objective-c - UITableView无法无法显示在屏幕中

 许先生不会再想过去的事观_307 发布于 2022-10-25 07:12

如下代码有什么问题吗?
我无法将数据显示在模拟器上,怎么办?

import "ViewController.h" import "ZYStatus.h"

@interface ViewController ()
@property(nonatomic,strong)NSArray *status;
@end

@implementation ViewController

-(NSArray *)status
{

if (_status == nil) {
    _status = [ZYStatus array];
}
return _status;

}

  • (void)viewDidLoad {

    [super viewDidLoad];
    self.tableView.rowHeight = 80;
    NSLog(@"11");

    }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [self.status count];

}

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

NSLog(@"13");
static NSString *cellId  = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}

ZYStatus *status1 = self.status[indexPath.row];
cell.textLabel.text = status1.name;
return cell;

}
@end

import

@interface ZYStatus : NSObject

@property(nonatomic,copy)NSString *text;
@property(nonatomic,copy)NSString *icon;
@property(nonatomic,copy)NSString *name;
@property(nonatomic,copy)NSString *picture;
@property(nonatomic,assign) BOOL vip;

-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)statusWithDict:(NSDictionary *)dict;
+(NSArray *)array;

@end

import "ZYStatus.h"

@implementation ZYStatus

-(instancetype)initWithDict:(NSDictionary *)dict
{

self = [super init];
if (self) {
    [self setValuesForKeysWithDictionary:dict];
}
return self;

}
+(instancetype)statusWithDict:(NSDictionary *)dict
{

return [[self alloc] initWithDict:dict];

}

+(NSArray *)array
{

NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses.plist" ofType:nil]];
NSMutableArray *arrayM;
for (NSDictionary *dict in array1)
{
[arrayM addObject:[self statusWithDict:dict]];
}
return arrayM;

}

@end

2 个回答
  • NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses" ofType:“plist”]];
    文件解析的时候,pathForResource后面跟的是文件名"statuses",ofType后面跟的是文件的后缀"plist"

    2022-10-26 14:29 回答
  • NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses" ofType:“plist”]];

    2022-10-26 14:30 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有