2012-04-02 17 views
5

Tôi đang phát triển một ứng dụng mà tôi phải hiển thị iAds trong tất cả các trang trong ứng dụng của mình .. Tôi đã tạo một lớp con của UIView nơi tôi đang khởi tạo ADBannerView và các phương thức ủy nhiệm của nó.Làm cách nào để iAd được xem trên toàn cầu trong ứng dụng của tôi?

Nhưng bây giờ nếu tôi thêm nó vào cửa sổ trong lớp appdelegate nó đem lại cho tôi sau lỗi tại thời gian chạy "ADBannerView phải là một phần của một hệ thống quan điểm của một UIViewController quản lý" ..

Tôi nghĩ bình này Tôi có thể sử dụng ADBanner chỉ trong tập tin subclass UIViewController của ??

nếu có thì làm thế nào tôi có thể tạo ra toàn cầu?

Cảm ơn trước Shreya

+1

Ngoài ra hãy xem câu trả lời được chấp nhận tại đây: http://stackoverflow.com/questions/9422177/is-it-a-good-practice-to-delete-the-adbannerview-on-viewwilldisappear-and-add- nó/9422360 # 9422360 –

+0

Hey @ user1036925: nếu bạn nhận được câu trả lời từ bài đăng bên dưới. vui lòng chấp nhận nó. :) –

+0

@shreya: làm cho nó trên cửa sổ trên appdelegate sau đó nó có thể .....! –

Trả lời

6

Trong lớp appdelegate bạn có thể làm cho một đối tượng chia sẻ.

- (ADBannerView *) sharedBannerView 
{ 
    if (_sharedBannerView == nil) 
    { 
     Class classAdBannerView = NSClassFromString(@"ADBannerView"); 

     if (classAdBannerView != nil) 
     { 
      _sharedBannerView = [[classAdBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)]; 

      // pre 4.2 doesn't have the new AdBannerSize constants. 
      if (&ADBannerContentSizeIdentifierPortrait != NULL) 
      { 
       [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]];    
      } 
      else 
      { 
       [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]];    
      } 
     } 
    } 

    ((ADBannerView *)_sharedBannerView).backgroundColor = [UIColor whiteColor]; 

    return _sharedBannerView; 
} 

Và thêm đối tượng được chia sẻ này vào chế độ xem bất cứ nơi nào bạn cần hiển thị iAds. Hy vọng bạn nhận được nó.

+0

Hi Neelam. thanx cho câu trả lời của bạn. Tôi sẽ thực hiện nó chắc chắn .. – Shreya

+0

@ user1036925: cũng hãy xem lưu ý kỹ thuật này từ Apple: [TN2286: Triển khai biểu ngữ iAd được chia sẻ] (https://developer.apple.com/library/ios/#technotes/ tn2286/_index.html # // apple_ref/doc/uid/DTS40011212) –