两个 NSLog 都在viewWillAppear
显示numberOfRowsInSection
我想在 tableView 中填充的数据。
我认为这个问题与返回正确的计数有关,但是由于 NSLogs 匹配,我不确定这是问题所在。
另外,我认为这是问题所在,因为cellForRowAtIndexPath
没有被调用。
我没有正确重新加载我的 tableView 吗?非常感谢帮忙。
#import "MainQueryViewController.h"
#import <Parse/Parse.h>
#import "SVProgressHUD.h"
#import "HHPanningTableViewCell.h"
#import "HHInnerShadowView.h"
#import "HHDirectionPanGestureRecognizer.h"
@interface MainQueryViewController () <PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, HHPanningTableViewCellDelegate>
@end
@implementation MainQueryViewController
@synthesize listArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
login.delegate = self;
login.signUpController.delegate = self;
[self presentModalViewController:login animated:NO];
}
-(void)viewWillAppear:(BOOL)animated {
PFQuery *query = [PFQuery queryWithClassName:@"ListItem"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[query whereKey:@"listName" equalTo:[PFUser currentUser]];
listArray = [objects mutableCopy];
NSLog(@"I'm about to show you an array");
NSLog(@"%@", listArray);
}
else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSInteger directionMask = indexPath.row % 5;
if (cell == nil) {
NSLog(@"Cell = nil.");
cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];
drawerView.backgroundColor = [UIColor greenColor];
cell.textLabel.text = [listArray objectAtIndex:indexPath.row];
cell.drawerView = drawerView;
// Configure the cell...
}
if (directionMask < 3) {
cell.directionMask = directionMask;
}
else {
cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;
if (directionMask == 4) {
cell.delegate = self;
}
}
cell.textLabel.text = [self.listArray objectAtIndex:directionMask];
return cell;
}
#pragma mark - PFLogInViewController delegate
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user
{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Successfully logged in.");
[SVProgressHUD showSuccessWithStatus:@"Success!"];
}];
}
- (void)logInViewControllerDidCancelLogIn:(PFLogInViewController *)logInController
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Login was cancelled!");
}
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Successfully signed up.");
}
- (void)signUpViewControllerDidCancelSignUp:(PFSignUpViewController *)signUpController
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Sign up was cancelled!");
}
#pragma mark - Table view delegate
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[HHPanningTableViewCell class]]) {
HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;
if ([panningTableViewCell isDrawerRevealed]) {
return nil;
}
}
return indexPath;
}
- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
message:@"You triggered a custom action"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
PFQuery *query = [PFQuery queryWithClassName:@"ListItem"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[query whereKey:@"listName" equalTo:[PFUser currentUser]];
listArray = [objects mutableCopy];
NSLog(@"I'm about to show you an array");
NSLog(@"%@", listArray);
}
else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
NSLog(@"This is a count of listArray");
NSLog(@"%@", listArray);
return [listArray count];
}
@end