首頁  >  問答  >  主體

objective-c - UITableView無法無法顯示在螢幕中

如下程式碼有什麼問題嗎?
我無法將資料顯示在模擬器上,該怎麼辦?

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;

}

-(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

阿神阿神2758 天前612

全部回覆(2)我來回復

  • 给我你的怀抱

    给我你的怀抱2017-04-25 09:05:45

    NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses" ofType:「plist」]];

    回覆
    0
  • 给我你的怀抱

    给我你的怀抱2017-04-25 09:05:45

    NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses" ofType:「plist」];
    檔案解析的時候,pathForResource後面跟的是檔案名稱"statuses",則是後的類型文件的字尾"plist"

    回覆
    0
  • 取消回覆