Как встроить UITableView в UIScrollview

Как я могу сделать следующее в UIViewController (содержащем табличное представление в качестве подпредставления)

У меня изначально есть UIViewController, показывающий раздел предварительного просмотра (UIView)

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

Я также добавил UITableView (и панель поиска ) ниже

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

enter image description here

С этой настройкой моя область прокрутки мала (только статическая область ниже раздела предварительного просмотра)

Как я могу изменить свой код, чтобы 1) Я могу прокручивать всю страницу вверх, т.е. раздел предварительного просмотра и табличное представление будут прокручиваться вверх вместе. 2) Прокрутка в целом остановится, когда панель поиска достигнет верхней части (под панелью навигации) (см. снимок экрана), но содержимое в UITableView по-прежнему прокручивается.

enter image description here

РЕДАКТИРОВАТЬ:

Добавлен код для представления UIScroll. Однако для меня ничего не изменилось. Что не так с моим кодом?

//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];
17
задан Zhen 9 May 2012 в 01:43
поделиться