菜鸟教程小白 发表于 2022-12-12 12:30:05

ios - tinderSwipeCards 数组人口


                                            <p><p>我正在使用 <a href="https://github.com/cwRichardKim/TinderSimpleSwipeCards" rel="noreferrer noopener nofollow">https://github.com/cwRichardKim/TinderSimpleSwipeCards</a> .我在 viewController 中创建了一个数组,其中数据来自 JSON。我希望只有该数量的卡片将创建为我的 JSON 数组中的数据。请帮助我,我从过去 3 天开始这样做,但尚未成功。</p>

<p>这是我的 ViewController 中的数组</p>

<pre><code>;
                     //;

                     NSLog(@&#34;%@&#34;,_arrAllCards);

                     //_draggableVC.allCards = _arrAllCards;


                     //;
                     if ( &gt;0) {

                         DraggableViewBackground *draggableBackground = [initWithFrame:self.invitationViewContainer.frame];


                        draggableBackground.exampleCardLabels = ;
                         draggableBackground.alpha = 0; //opti
                         ;

                         ;
                     }
</code></pre>

<p>而 DraggableViewBackground 是 cwRichardKim 提供的 View 类</p>

<pre><code>   - (id)initWithFrame:(CGRect)frame
{

self = ;
if (self) {
    ;
    ;

    exampleCardLabels =;//%%% placeholder for card-specific information
    loadedCards = [ init];
    allCards = [ init];
    cardsLoadedIndex = 0;
    ;
}
return self;
   }

    //%%% sets up the extra buttons on the screen



// to get rid of it (eg: if you are building cards from data from the internet)
      -(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index
      {

   //MGInvitationModel *model = self.exampleCardLabels;

      DraggableView *draggableView = [initWithFrame:CGRectMake(0, -50, CARD_WIDTH,CARD_HEIGHT)];//[initWithFrame:CGRectMake((self.bounds.size.width)/2, (self.bounds.size.height)/2, CARD_WIDTH, CARD_HEIGHT)]; //[initWithFrame:CGRectMake(0, -40, CARD_WIDTH, CARD_HEIGHT)];
   //draggableView.information.text = ;      //%%% placeholder for card-specific information



   draggableView.delegate = self;
   draggableView.layer.cornerRadius = 10.0f;


    nameLabel = [initWithFrame:CGRectMake(30, 280, 150, 50)];
   nameLabel.font = ;
   nameLabel.text = @&#34;NIVESH&#34;;
   ;
      nameLabel.textColor = ;

;
return draggableView;



}




   //%%% loads all the cards and puts the first x in the &#34;loaded cards&#34; array
   -(void)loadCards
       {




if( &gt; 0) {
    NSInteger numLoadedCardsCap =(( &gt; MAX_BUFFER_SIZE)?MAX_BUFFER_SIZE:);
    //%%% if the buffer size is greater than the data size, there will be an array error, so this makes sure that doesn&#39;t happen



    //%%% loops through the exampleCardsLabels array to create a card for each label.This should be customized by removing &#34;exampleCardLabels&#34; with your own array of data
    for (int i = 0; i&lt;; i++) {
      DraggableView* newCard = ;
      ;

      if (i&lt;numLoadedCardsCap) {
            //%%% adds a small number of cards to be loaded
            ;
      }
    }



    //%%% displays the small number of loaded cards dictated by MAX_BUFFER_SIZE so that not all the cards
    // are showing at once and clogging a ton of data
    for (int i = 0; i&lt;; i++) {
      if (i&gt;0) {
             belowSubview:];
      } else {
            ];
      }
      cardsLoadedIndex++; //%%% we loaded a card into loaded cards, so we have to increment
    }
}else if ( == 0){

    ;
    //;
    }
   }

   #warning include own action here!
   //%%% action called when the card goes to the left.
   // This should be customized with your own action
    -(void)cardSwipedLeft:(UIView *)card;
   {
//do whatever you want with the card that was swiped
//    DraggableView *c = (DraggableView *)card;

    ; //%%% card was swiped, so it&#39;s no       longer a &#34;loaded card&#34;

      if (cardsLoadedIndex &lt; ) { //%%% if we haven&#39;t reached the end of all cards, put another into the loaded cards
    ];
    cardsLoadedIndex++;//%%% loaded a card, so have to increment count
    belowSubview:];
}
   }

      #warning include own action here!
   //%%% action called when the card goes to the right.
    // This should be customized with your own action
    -(void)cardSwipedRight:(UIView *)card
   {
//do whatever you want with the card that was swiped
//    DraggableView *c = (DraggableView *)card;

    ; //%%% card was swiped, so it&#39;s nolonger a &#34;loaded card&#34;

   if (cardsLoadedIndex &lt; ) { //%%% if we haven&#39;t reached the end of all cards, put another into the loaded cards
    ];
    cardsLoadedIndex++;//%%% loaded a card, so have to increment count
    belowSubview:];
}

}

   //%%% when you hit the right button, this is called and substitutes the swipe
    -(void)swipeRight
      {
DraggableView *dragView = ;
dragView.overlayView.mode = GGOverlayViewModeRight;
[UIView animateWithDuration:0.2 animations:^{
    dragView.overlayView.alpha = 1;
}];
;
   }

//%%% when you hit the left button, this is called and substitutes the swipe
   -(void)swipeLeft
{
DraggableView *dragView = ;
dragView.overlayView.mode = GGOverlayViewModeLeft;
[UIView animateWithDuration:0.2 animations:^{
    dragView.overlayView.alpha = 1;
}];
;
}

    -(void)swipeIgnore
{
DraggableView *dragView = ;
dragView.overlayView.mode = GGOverlayViewModeLeft;
[UIView animateWithDuration:0.2 animations:^{
    dragView.overlayView.alpha = 1;
}];
;


   }

   /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
   - (void)drawRect:(CGRect)rect
   {
// Drawing code
   }
   */
</code></pre>

<p>@结束</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你能像这样改变你的 -(void)loadCards 方法吗-</p>

<pre><code>-(void)loadCards :(NSArray*) array {
   exampleCardLabels = array;

   //put here your existing code.
   //...
}
</code></pre>

<p>还在 DraggableViewBackground.h 文件中添加 <code>-(void)loadCards :(NSArray*) array;</code></p>

<p>并注释 <code>;</code> 来自 <code>- (id)initWithFrame:(CGRect)frame</code> 方法</p>

<p>然后像这样改变这个方法-</p>

<pre><code>if ( &gt;0) {

                         DraggableViewBackground *draggableBackground = [initWithFrame:self.invitationViewContainer.frame];

                         ;
                         draggableBackground.alpha = 0; //opti
                         ;

                         //;
                     }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - tinderSwipeCards 数组人口,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40926460/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40926460/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - tinderSwipeCards 数组人口