2016-12-17 3 views
0

私はobjective-cを使ってXcodeでアプリケーションを開発しています。私の問題は、ToolBarを使用して私のUITableViewControllerでadmob広告を表示しようとしていますが、このバーに何も表示されていないことです。私はこのツールバーをUITableViewControllerに配置する方法について、インターネット上で多くの回答を見つけましたが、私の場合は何も表示されていません。私はXcodeのレベルが低いことを知っていますが、私は毎日の改善を図っています。ToolBarのAdmob UITableViewController Xcode

これは、AdMobのためのコードの私の作品です:

[self.navigationController setToolbarHidden:NO]; 
    self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; 
    self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; //TEST!!!!! 
    self.bannerView.rootViewController = self; 
    [self.navigationController.toolbar addSubview:self.bannerView]; 

    GADRequest *request = [GADRequest request]; 
    request.testDevices = @[ @"",]; 
    [self.bannerView loadRequest:request]; 

これは私のMainTableViewController.hです:

#import <UIKit/UIKit.h> 
#import "Restaurant.h" 

@import GoogleMobileAds; 
@interface MainTableViewController : UITableViewController 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *barButton; 
@property (nonatomic, strong) NSArray<Restaurant *> *originData; 
@property (nonatomic, strong) NSMutableArray<Restaurant *> *filteredRest; 
@property (nonatomic, assign) Boolean isFiltered; 
@property (weak, nonatomic) IBOutlet UISearchBar *mySearchBar; 
@property (strong, nonatomic) IBOutlet UITableView *RestTableView; 
@property (weak, nonatomic) IBOutlet UIToolbar *admobToolBar; 
@property(weak, nonatomic) IBOutlet GADBannerView *bannerView; 

@end 

そして、これは私のMainTableviewController.mです:

#import "MainTableViewController.h" 
    #import "SWRevealViewController.h" 
    #import "RestTableViewCell.h" 
    #import "RestViewController.h" 
    #import "Restaurant.h" 

    @interface MainTableViewController() 
    @end 
    @implementation MainTableViewController 

    @synthesize mySearchBar, filteredRest, isFiltered, originData; 

    - (void)viewDidLoad { 
     [super viewDidLoad]; 

     _barButton.target = self.revealViewController; 
     _barButton.action = @selector(revealToggle:); 

     [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 

     self.RestTableView.tableFooterView = [[UIView alloc] init]; /*Esta linea hace que en la tabla solo aparezcan el numero de filas que tienes establecidas, es decir, que las vacias no aparezcan*/ 



     [self.navigationController setToolbarHidden:NO]; 
     self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; 
     self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; //TEST!!!!! 
     //self.bannerView.adUnitID = @"ca-app-pub-6926442062866079/7221537141"; 
     self.bannerView.rootViewController = self; 
     [self.navigationController.toolbar addSubview:self.bannerView]; 
     GADRequest *request = [GADRequest request]; 
     request.testDevices = @[ @"",]; 
     [self.bannerView loadRequest:request]; 

     originData = @[ 
      [[Restaurant alloc] init:@"80 Grados" descripiton:@"Malasaña" image:@"80_grados.jpg"], 
      [[Restaurant alloc] init:@"90 Grados" descripiton:@"Retiro" image:@"90_grados.jpg"], 
      [[Restaurant alloc] init:@"B&B Babel" descripiton:@"Barrio de Chueca" image:@"babel.jpg"], 
      [[Restaurant alloc] init:@"Babelia" descripiton:@"Barrio de Salamanca" image:@"babelia.jpg"], 
      [[Restaurant alloc] init:@"Bacira" descripiton:@"Chamberí" image:@"bacira.jpg"], 
      [[Restaurant alloc] init:@"Bar Galleta" descripiton:@"Malasaña" image:@"bar_galleta.jpg"], 
      [[Restaurant alloc] init:@"Bar Tomate" descripiton:@"Chamberí" image:@"bar_tomate.jpg"], 

     filteredRest = [NSMutableArray new]; 
     isFiltered = NO; 

    } 
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     // Return the number of sections. 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     // Return the number of rows in the section. 
     if (isFiltered == YES) { 
      return filteredRest.count; 
     } else { 
      return originData.count; 
     } 
    } 


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *CellIdentifier = @"TableCell"; 
     RestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

     // Configure the cell... 
     if (isFiltered == YES) { 
      cell.TitleLabel.text = [filteredRest objectAtIndex:indexPath.row].title; 
      cell.DescriptionLabel.text = [filteredRest objectAtIndex:indexPath.row].desc; 
      cell.RestImage.image = [UIImage imageNamed:[filteredRest objectAtIndex:indexPath.row].image]; 
     } else { 
      cell.TitleLabel.text = [originData objectAtIndex:indexPath.row].title; 
      cell.DescriptionLabel.text = [originData objectAtIndex:indexPath.row].desc; 
      cell.RestImage.image = [UIImage imageNamed:[originData objectAtIndex:indexPath.row].image]; 
     } 

     cell.RestImage.layer.cornerRadius = 6; 
     cell.RestImage.clipsToBounds = YES; 
     cell.RestImage.layer.borderWidth = 1; 

     return cell; 
    } 


    -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    { 

     if ([[segue identifier] isEqualToString:@"ShowDetails"]){ 
      RestViewController *restviewcontroller = [segue destinationViewController]; 

      NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 

      if (isFiltered) { 
       restviewcontroller.DetailModal = filteredRest[myIndexPath.row]; 
      } else { 
       restviewcontroller.DetailModal = originData[myIndexPath.row]; 
      } 
     } 
    } 

@end 

ツールバーには何も表示されません:

enter image description here

何が間違っていますか? 私はあなたの助けが必要です!あなたの反応よりもずっとです!

答えて

0

この広告を表示するためにUIToolBarを使用する理由はありますか?

代わりにUITableViewControllerを使用し、UIViewControllerを使用して、そこにUITableViewのプロパティを作成することをお勧めします。

あなたがそうのようなセットアップは、あなたの制約ができることを行っているたら:

=====

トップ

テーブルビュー

広告ビュー(セット高さ)

下段

======

その中にテーブルビューでのUIViewControllerを使用することの利点は、あなただけのテーブルビュー、画面上の任意の他のない置くことができるということです:)

私はそれが役に立てば幸い!あなたがそれをどこから始めるべきかについてのより多くの情報が必要な場合は、お気軽にご返信ください!

関連する問題