Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to embed a UITableView in a UIScrollview
    primarykey
    data
    text
    <p>How can I do the following in a UIViewController (containing a tableview as a subview)</p> <p>I initially have a UIViewController showing a preview section (UIView)</p> <pre><code>//Setup container for preview section UIView *tempContainer = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 320, 100)]; self.preview_answer_container = tempContainer; self.preview_answer_container.backgroundColor = [UIColor clearColor]; [tempContainer release]; [self.view addSubview:self.preview_answer_container]; </code></pre> <p>I also added a UITableView (and a searchbar) below</p> <pre><code>//setup tableview UITableView *tempTable = [[UITableView alloc]initWithFrame:CGRectMake(0,44 ,320,self.view.frame.size.height - 44)]; self.tagFriendsTableView = tempTable; self.tagFriendsTableView.delegate = self; self.tagFriendsTableView.dataSource = self; [tempTable release]; [self.view addSubview:self.tagFriendsTableView]; </code></pre> <p><img src="https://i.stack.imgur.com/C4wbr.png" alt="enter image description here"></p> <p>With this setup, my scrolling area is small (only static area below preview section)</p> <p>How can I modify my code such that 1) I can scroll the whole page upwards i.e. preview section and tableview will scroll up together 2) Scrolling as a whole will stop when the search bar reaches the top (below navbar) (see screenshot), but the contents in the UITableView is still scrollable</p> <p><img src="https://i.stack.imgur.com/Tn7O4.png" alt="enter image description here"></p> <p>EDIT:</p> <p>Added code for UIScroll view. However, nothing changed for me. What is wrong with my code?</p> <pre><code>//setup scroll view UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; //Search UISearchBar *tempBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 120 + 20, 320, 44)]; self.sBar = tempBar; [tempBar release]; self.sBar.delegate = self; self.sBar.tintColor = [UIColor colorWithHexString:@"#b6c0c7"]; self.sBar.placeholder = @"Search for FB and DM friends"; [scroll addSubview:sBar]; //setup tableview UITableView *tempTable = [[UITableView alloc]initWithFrame:CGRectMake(0,144 + 20 + 20 ,320,self.view.frame.size.height - 144 - 20 - 20 - 44)]; self.tagFriendsTableView = tempTable; self.tagFriendsTableView.delegate = self; self.tagFriendsTableView.dataSource = self; [tempTable release]; //Add the scroll view to the parent view [scroll addSubview:self.tagFriendsTableView]; scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height); [self.view addSubview:scroll]; [scroll release]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload