2016-08-17 2 views
0

iOSプログラミングの新機能です。私の質問がとても素朴に聞こえる場合は、事前に申し訳ありません。私はUITableViewCellに2つのカスタムセルを持っています。 1つは画像とラベルと他の表示バナーを表示する。私は、3つのセルに画像を持つラベルを表示し、その後バナーを表示して、これを続けます。2つのカスタムセルを持つUITableViewCell - 画像が変更され続ける

現在のところ、私はそれを表示することができますが、スクロールすると、イメージとバナーはセル内の位置を変更します。続き

は私のコードです: -

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    if VideosTableViewController.flag >= 1 { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell 

     let remoteImageUrlString = imageCollection[indexPath.row] 
     let imageUrl = NSURL(string:remoteImageUrlString) 

     let myBlock: SDWebImageCompletionBlock! = {(image:UIImage!, error: NSError!, cachetype:SDImageCacheType!, imageURL: NSURL!) -> Void in 
     } 
     //cell.myImageView?.image = nil 

     cell.myImageView.sd_setImageWithURL(imageUrl, completed: myBlock) 

     //set label 
     cell.myImageLabel.text = labelCollection[indexPath.row] 
     print(cell.myImageLabel?.text) 

     VideosTableViewController.flag = VideosTableViewController.flag - 1 

     return cell 
      } 
    else 
    { 
     let adCell = tableView.dequeueReusableCellWithIdentifier("adCell", forIndexPath: indexPath) as! VideosBannerAdCustomTableViewCell 

     VideosTableViewController.flag = VideosTableViewController.flag + 3 

      VideosTableViewController.flag = 3 


     adCell.videosBannerView.adUnitID = "banner id" 
     adCell.videosBannerView.rootViewController = self 
     let request : DFPRequest = DFPRequest() 
     //request.testDevices = [kGADSimulatorID] 
     request.testDevices = ["my test device id"] 
     adCell.videosBannerView.loadRequest(request) 

     return adCell 

    } 
    } 
+0

あなたはGIF画像を投稿することができますか? –

+0

申し訳ありませんgifをアップロードできません。今日このグループに参加していて、まだ10の評判はありません:( – Molly

答えて

1

使用すべきセルを決定するためにindexPathを使用するようにしてください。あなたは....、セル4日、8日でバナーとadCellを表示しようとしているので、このことによって行うことが非常に簡単です:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    if indexPath.row % 4 != 0 || indexPath.row == 0 { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell 

     let remoteImageUrlString = imageCollection[indexPath.row] 
     let imageUrl = NSURL(string:remoteImageUrlString) 

     let myBlock: SDWebImageCompletionBlock! = {(image:UIImage!, error: NSError!, cachetype:SDImageCacheType!, imageURL: NSURL!) -> Void in 
     } 
     //cell.myImageView?.image = nil 

     cell.myImageView.sd_setImageWithURL(imageUrl, completed: myBlock) 

     //set label 
     cell.myImageLabel.text = labelCollection[indexPath.row] 
     print(cell.myImageLabel?.text) 

     VideosTableViewController.flag = VideosTableViewController.flag - 1 

     return cell 
      } 
    else 
    { 
     let adCell = tableView.dequeueReusableCellWithIdentifier("adCell", forIndexPath: indexPath) as! VideosBannerAdCustomTableViewCell 

     VideosTableViewController.flag = VideosTableViewController.flag + 3 

      VideosTableViewController.flag = 3 


     adCell.videosBannerView.adUnitID = "banner id" 
     adCell.videosBannerView.rootViewController = self 
     let request : DFPRequest = DFPRequest() 
     //request.testDevices = [kGADSimulatorID] 
     request.testDevices = ["my test device id"] 
     adCell.videosBannerView.loadRequest(request) 

     return adCell 

    } 
    } 
+0

indexPath.row = 3、7、11などのバナーでadCellを表示したいのです。セルを使用してください。 – Molly

+0

簡単に、あなたはこのロジックを行う方法を理解する必要があります。 – sahara108

関連する問題