objective-c - UITableView无法无法显示在屏幕中
阿神
阿神 2017-04-25 09:03:45
0
2
564

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

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 <Foundation/Foundation.h>

@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

阿神
阿神

闭关修行中......

membalas semua(2)
给我你的怀抱

NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status" ofType:“plist”]];

给我你的怀抱

NSArray *array1 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses" ofType:"plist"]];
Apabila menghuraikan fail, pathForResource diikuti dengan nama fail "statuses", ofType Ia diikuti dengan akhiran fail "plist"

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!