0

I'm using the ZLSwipeableView library to get a list of "cards" that I can swipe between, like Tinder. I'm setting up a connection to a Class on Parse.com and for each card I want to return a row from Parse. I can't figure out what I'm doing wrong. The name label on every card is just empty. Here's how I'm doing it:

@interface HomeViewController () <ZLSwipeableViewDataSource,
ZLSwipeableViewDelegate, UIActionSheetDelegate> {
    NSDictionary *dic;
    NSString *str;
}

@property (nonatomic, retain) NSArray *users;

@property (nonatomic, weak) IBOutlet ZLSwipeableView *swipeableView;
@property (nonatomic, strong) NSArray *colors;
@property (nonatomic) NSUInteger colorIndex;
@property (nonatomic) BOOL loadCardFromXib;
@property (nonatomic, retain) PFQuery *query;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.cardDelegate = self;

    self.colorIndex = 0;

    PFQuery *query = [PFQuery queryWithClassName:@"Users"];

    [query includeKey:@"user"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {

        if (!error) {
            self.users = posts;
            NSLog(@"%@", posts);
        } else {

        }
    }];

    self.users = @[@""];
    self.swipeableView.delegate = self;
}

#pragma mark - ZLSwipeableViewDelegate

- (void)swipeableView:(ZLSwipeableView *)swipeableView
         didSwipeView:(UIView *)view
          inDirection:(ZLSwipeableViewDirection)direction {
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
       didCancelSwipe:(UIView *)view {
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
  didStartSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
          swipingView:(UIView *)view
           atLocation:(CGPoint)location
          translation:(CGPoint)translation {
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
    didEndSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
}

#pragma mark - ZLSwipeableViewDataSource

- (UIView *)nextViewForSwipeableView:(ZLSwipeableView *)swipeableView {
    if (self.colorIndex < self.companies.count) {

        _cardDelegate = self;
        CardView *view = [[CardView alloc] initWithFrame:swipeableView.bounds];
        view.cardDelegate = self;
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];

        PFQuery *query = [PFQuery queryWithClassName:@"Users"];

        [query includeKey:@"user"];

        [query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {

            if (!error) {
                self.users = posts;
                dic = [self.users objectAtIndex:0];
                str = [dic objectForKey:@"name"];
            } else {

            }
        }];

        UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, 280, 30)];

        //Here's where I want to return each name for every card. But the label is just empty
        NSDictionary *dic = self.colors[self.colorIndex];
        nameL.text = [dic objectForKey:@"name"];

        nameL.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:32];
        nameL.numberOfLines = 1;
        nameL.baselineAdjustment = UIBaselineAdjustmentAlignBaselines;
        nameL.adjustsFontSizeToFitWidth = YES;
        nameL.adjustsLetterSpacingToFitWidth = YES;
        nameL.minimumScaleFactor = 10.0f/12.0f;
        nameL.clipsToBounds = YES;
        nameL.backgroundColor = [UIColor clearColor];
        nameL.textColor = [UIColor darkGrayColor];
        nameL.textAlignment = NSTextAlignmentCenter;
        [view addSubview:nameL];

        self.colorIndex++;

        if (self.loadCardFromXib) {
            UIView *contentView =
            [[[NSBundle mainBundle] loadNibNamed:@"CardContentView"
                                           owner:self
                                         options:nil] objectAtIndex:0];
            contentView.translatesAutoresizingMaskIntoConstraints = NO;
            [view addSubview:contentView];

            NSDictionary *metrics = @{
                                      @"height" : @(view.bounds.size.height),
                                      @"width" : @(view.bounds.size.width)
                                      };
            NSDictionary *views = NSDictionaryOfVariableBindings(contentView);
            [view addConstraints:
             [NSLayoutConstraint
              constraintsWithVisualFormat:@"H:|[contentView(width)]"
              options:0
              metrics:metrics
              views:views]];
            [view addConstraints:[NSLayoutConstraint
                                  constraintsWithVisualFormat:
                                  @"V:|[contentView(height)]"
                                  options:0
                                  metrics:metrics
                                  views:views]];
        } else {
        }

        return view;
    }
    return nil;
}

@end
tracifycray
  • 1,423
  • 4
  • 18
  • 29
  • `self.colors[self.colorIndex];` is the first mention of colors in the posted code. – danh Apr 08 '15 at 15:02
  • Yes. Not really sure what you mean @danh – tracifycray Apr 08 '15 at 15:12
  • If I understand the question, it is about `nameL.text` not being set as expected. Working backwards, that depends on `dic` being set to what you expect and that depends on `self.colors`. But what do we know about how `self.colors` gets assigned? Searching the page, I see only the declaration, nothing else. – danh Apr 08 '15 at 17:44

0 Answers0