2011-08-20 81 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,为什么它丢失?我不需要它吗? –