定义:@property(copy, nonatomic) NSMutableArray*prjlist;
@property(nonatomic, strong) UITableView*mytable;
@property(strong, nonatomic) NSArray*tasks;调用:#import "TestViewController.h"
#import "MKNetworkKit.h"@implementation TestViewController- (void)viewDidLoad
{
[superviewDidLoad];
self.mytable.delegate = self;
self.mytable.dataSource = self;
self.tasks= @[@"Walk the log", @"URGENT:Buy milk", @"Clean hidden lair"];
MKNetworkEngine*engine = [[MKNetworkEnginealloc] initWithHostName:@"192.168.0.77:8030/Service1.svc"customHeaderFields:nil];
MKNetworkOperation*op = [engine operationWithPath:@"/PrjStr/0/1/15"params:nilhttpMethod:@"GET"ssl:NO];
[op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
NSData *data = [completedOperation responseData];
NSDictionary*resdict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];
self.prjlist = [resdict objectForKey:@"col"];
[self.mytable reloadData];
} errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
NSLog(@"MKNetwork request error : %@", [error localizedDescription]);
}];
[engine enqueueOperation:op];}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%i", self.prjlist.count);
//return [self.prjlist count];
return [self.tasks count];
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"plainCell";
NSString *task = [self.tasks objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = task;
return cell;
}
这段代码 reloadData不执行! 盼指点
用的是Storyboard, 有个TableViewCell -plainCell Identifier是plainCell, 我还有哪里做的不对呢?
@property(nonatomic, strong) UITableView*mytable;
@property(strong, nonatomic) NSArray*tasks;调用:#import "TestViewController.h"
#import "MKNetworkKit.h"@implementation TestViewController- (void)viewDidLoad
{
[superviewDidLoad];
self.mytable.delegate = self;
self.mytable.dataSource = self;
self.tasks= @[@"Walk the log", @"URGENT:Buy milk", @"Clean hidden lair"];
MKNetworkEngine*engine = [[MKNetworkEnginealloc] initWithHostName:@"192.168.0.77:8030/Service1.svc"customHeaderFields:nil];
MKNetworkOperation*op = [engine operationWithPath:@"/PrjStr/0/1/15"params:nilhttpMethod:@"GET"ssl:NO];
[op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
NSData *data = [completedOperation responseData];
NSDictionary*resdict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];
self.prjlist = [resdict objectForKey:@"col"];
[self.mytable reloadData];
} errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
NSLog(@"MKNetwork request error : %@", [error localizedDescription]);
}];
[engine enqueueOperation:op];}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%i", self.prjlist.count);
//return [self.prjlist count];
return [self.tasks count];
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"plainCell";
NSString *task = [self.tasks objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = task;
return cell;
}
这段代码 reloadData不执行! 盼指点
用的是Storyboard, 有个TableViewCell -plainCell Identifier是plainCell, 我还有哪里做的不对呢?
@property (nonatomic,weak) IBOutlet UITableView*mytable;
在storyboard中连线"插座变量"mytable 到页面上的UITableView控件。