开发者

Could Not able to position the UITableView?

- (void)loadView 
{

       SettingsTitleBar=[[UINavigationController alloc] initWithRootViewController: self];
        searchBar =[ [UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 40)];
    searchBar.placeholder = @"Type your City Name";
    searchBar.delegate = self;
    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    [searchBar setShowsCancelButton:YES];
    [SettingsTitleBar.navigationBar addSubview:searchBar];  
        self.view = [[UIView alloc]  initWithFrame:CGRectMake(0, 85, 320, 392)]; 
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 120, 320, 302)                                                         style: UITableViewStyleGrouped]; 
    [tableView setDelegate:self]; 
    [tableView setDataSource:self]; 
        [self.view addSubview:tableView];


}

I Have a UITableViewController, I have utilized the first 44 pixels height for title bar, and then the next 40 pixels of height for search bar(44+40). These are added as navigation control开发者_运维知识库ler subviews. then i am adding my self.view at 85 pixel from top, finally tableview has been added as child to the self.view . But table view has been overlapped with the Searchbar. I dont what is wrong with it. I tried to change various yPositions of tableview and self.view but still nothing happened. Can anyone able to help me out from this ?

Note : I dont want to add SearchBar into UITableviewHeader Section.


U can make the view of size 320X436 and add the tabble view and search bar in that view...


I wouldn't add subviews to the navigationBar. Add it to the view.

As a sidenote: anything you alloc (or retain or copy), you should release or autorelease


I had trouble with this too, initially. Don't worry about adding the searchBar as a subview. Simply do this:

self.tableView.tableHeaderView = searchBar;

The searchBar will be treated like a header. You'll want to change the CGRect's size to (0,0,320,44), however.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜