开发者

Add a UITableViewControler to a UIView

I am writing an appcelerator module, which means I am handed开发者_如何学Go a subclassed UIView to work with and create my visual controls in Objective C.

I am trying to add a tableview with a searchbar, but most samples online use rootViewController and UITableViewControler.

so...in order to add a tableview to the current view, do I need to create a tableview and a UITableViewController and add them somehow as subviews to the current view ?

I tried adding a MainViewController.h & MainViewController.m which is defined as

@interface MainViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>

and then in my view

#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];
    }
} 

but it did not work, I just got an empty view. any ideas ? a sample code would be greatly appreciated

thanks


You could try something like this:

- (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];

}

Hope this helps get you started...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜