2012-06-21 18 views
0

我正在嘗試更改我的UITableView的大小。我在廣告底部展示廣告,當我滾動廣告時,廣告隨之滾動。我想知道如何改變UITableView的大小,使廣告始終保持在視圖的底部,而不管UITableView是否被滾動。我試圖改變TableView框架的大小,但這不起作用。更改UIViewTable的大小以適應AdWhirl廣告

- (void)viewDidAppear:(BOOL)animated 
{ 
tableView.frame = CGRectMake()... 
} 

我也試圖改變它在scrollViewDidScroll:選擇,但沒有運氣。無論如何,我可以改變高度,以免與底部的廣告衝突?謝謝!

+0

你使用IB做出的UITableView? –

回答

0

隨着UITableViewControllers self.view == self.tableView。這是你的情況,因爲你想要的效果需要兄弟視圖(兩個視圖添加到一個共同的超級視圖),但沒有「superview」self.tableView。

你必須創建具有一個UITableView和兩個子視圖廣告視圖的新UIViewController子類。您將需要處理諸如設置表視圖的數據源和委託,以及在控制器出現時取消選擇表視圖單元格。這是一個更多的工作,需要一些照顧,但絕對是可行的。

我一起引發低於一個簡單的例子將幫助您瞭解:

// Header 
@interface CustomTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> 
- (id)initWithStyle:(UITableViewStyle)tableViewStyle; 

@property (nonatomic, readwrite, retain) UITableView* tableView; 
@end 

// Source 
@interface CustomTableViewController() 
@property (nonatomic, readwrite, assign) UITableViewStyle tableViewStyle; 
@end 

@implementation CustomTableViewController 

@synthesize tableView; 
@synthesize tableViewStyle = _tableViewStyle; 

- (id)initWithStyle:(UITableViewStyle)tableViewStyle { 
    if ((self = [super initWithNibName:nil bundle:nil])) { 
    _tableViewStyle = tableViewStyle; 
    } 
    return self; 
} 

- (void)loadView { 
    [super loadView]; 

    self.tableView = [[UITableView alloc] initWithStyle:self.tableViewStyle]; 
    self.tableView.autoresizingMask = (UIViewAutoresizingMaskFlexibleWidth 
            | UIViewAutoresizingMaskFlexibleHeight); 
    self.tableView.delegate = self; 
    self.tableView.dataSource = self; 
    [self.view addSubview:self.tableView]; 

    // Create your ad view. 
    ... 

    adView.autoresizingMask = (UIViewAutoresizingMaskFlexibleWidth 
          | UIViewAutoresizingMaskFlexibleTopMargin); 
    [self.view addSubview:adView]; 

    [adView sizeToFit]; 
    self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - adView.frame.size.height); 
    adView.frame = CGRectMake(0, self.view.bounds.size.height - adView.frame.size.height, self.view.bounds.size.width, adView.frame.size.height); 

    [self.tableView reloadData]; 
} 

- (void)viewDidUnload { 
    self.tableView = nil; 

    [super viewDidUnload]; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    NSIndexPath* selectedIndexPath = [self.tableView indexPathForSelectedRow]; 
    if (nil != selectedIndexPath) { 
    [self.tableView deselectRowAtIndexPath:selectedIndexPath animated:animated]; 
    } 
} 

@end 
+0

我想這和我的觀點是黑色,並且沒有顯示在屏幕上了最終的幹活也調整它。 – kamran619

+0

您很可能需要實現自定義表格視圖控制器。 – featherless

+0

我對Objective-C非常陌生,不得不在明天推送一個應用程序給客戶端。有沒有簡單的快速方法來做到這一點? – kamran619

0

簡單的方法來解決這個問題,只是使用的.xib文件爲您的UITableView,然後你很容易改變高度使用Interface Builder。

如果你沒有IB文件,那麼請去通過這個帖子:How do I resize the UITableView's height dynamically?

+0

我已經嘗試動態編輯它並沒有使用界面生成器,但沒有運氣.. – kamran619

相關問題