2011-08-20 49 views
1

我寫的Appcelerator的模塊,這意味着我遞給子類的UIView的目的C.繼續努力,創造我的視覺控制一個UITableViewControler添加到一個UIView

我想添加一個tableview中有搜索欄,但大多數在線示例使用rootViewController和UITableViewControler。

所以...爲了添加一個tableview到當前視圖,我需要創建一個tableview和一個UITableViewController並將它們以某種方式添加爲當前視圖的子視圖嗎?

我嘗試添加其定義爲

@interface MainViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate> 

,然後在我看來

#import "MainViewController.h" 

- (void)viewDidLoad 
{ 
    mainView = [[MainViewController alloc] init]; 

    [self addSubview:mainView.view]; 
} 

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds 
{ 
    if(CGRectIsEmpty(self.frame)) 
    { 
     self.frame = bounds; 
     [self addSubview:mainView.view]; 
    } 
} 

一個MainViewController.h & MainViewController.m但它沒有工作,我只是得到了一個空視圖。有任何想法嗎 ?一個示例代碼將不勝感激

感謝

+0

你在哪裏設置'frame' for'mainView'? – EmptyStack

+0

呃..我沒有。我只是使用蘋果示例tableSearch(http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html)中的mainviewcontroller文件,我想如果我在我的視圖中運行該表,休息比較容易。我看了,他們沒有在這個示例中設置框架 –

+0

看起來,在示例中,mainView是從nib創建的。 '[[MainViewController alloc] initWithNibName:@「MainView」bundle:nil];' – EmptyStack

回答

1

你可以嘗試這樣的事:

- (void)viewDidLoad { 
self.view.backgroundColor=[UIColor whiteColor]; 


UITableView *TableListView=[[UITableView alloc] initWithFrame:CGRectMake(-5,-1,331,425) style:1]; 
TableListView.editing=NO; 
TableListView.delegate=self; 
TableListView.dataSource=self; 
TableListView.separatorColor=[UIColor colorWithRed:0.000000 green:0.591928 blue:1.000000 alpha:1.000000]; 
TableListView.separatorStyle=1; 
TableListView.rowHeight=40; 
TableListView.tag=0; 
TableListView.backgroundColor=[UIColor groupTableViewBackgroundColor]; 
TableListView.clipsToBounds=YES; 
[self.view addSubview:TableListView]; 
[TableListView release]; 

} 

希望這有助於讓你開始...

+0

謝謝!我會嘗試一下,讓你知道。順便說一句,你的示例代碼中沒有tableviewcontroller,爲什麼它丟失?我不需要它嗎? –

相關問題