我一直试图这样做几天而且卡住了。我使用解析作为我的后端。我不想使用parse自己的ParseTableView来设置我的View。在开始一个更难的应用程序之前,我想了解这个基本应用程序发生了什么。如何使用解析数据填充我的表???谢谢。
//
// ViewController.m
// BraveRetiredNumbers
//
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UITableView *playerTableView;
@property (strong, nonatomic) NSArray *testArrary;
@property (strong, nonatomic) NSString *parseClassName;
@end
@implementation ViewController
@synthesize testArrary;
@synthesize playerArray;
@synthesize playerTableView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self performSelector:@selector(retrieveFromParse)];
self.testArrary = @[@"Apple",@"Banana",@"Peach",@"Grape",@"Strawberry",@"Watermelon"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.playerArray count];
//return [testArrary count];
}
- (void) retrieveFromParse {
PFQuery *query = [PFQuery queryWithClassName:@"Player"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"%@\n",objects);
if (!error) {
playerArray = [[NSArray alloc] initWithArray:objects];
}
}];
[playerTableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[playerTableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleIdentifier = @"playerCell";
UITableViewCell *cell = [playerTableView dequeueReusableCellWithIdentifier:SimpleIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleIdentifier];
}
//PFObject *tempObject = [playerArray objectAtIndex:indexPath.row];
//NSDictionary *tempDic = [playerArray objectAtIndex:@"playerName"];
cell.textLabel.text = [tempDic objectForKey:@"playerName"];
//cell.textLabel.text = [testArrary objectAtIndex:indexPath.row];
return cell;
}
@end