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