Good time of day, such a problem arose, I have a scroll view, there are buttons / labels on the floor of the screen, the other half of the screen is occupied by the table, I want to make sure that the entire view is scrolling when you rewind the table, this is already the 2nd day I play with autoloyout, I can not do anything with it: (Good people, help please, I will be very grateful
4 answers
Try to put everything in the table. What you now have in scrollview, just send in a separate cell or footer / header and do not fool with the synchronization of these two controls.
- This option will not work, since there are a lot of elements on the page ( - Zarochintsev
- So what? Why is this option not suitable? This is almost perfect if you have data on the screen. Beat your view into pieces and draw it "line by line". - AlexDenisov
- Sorry for the stupid question, that is, you need to create, say, two cells, in the 1st map / labels / buttons and in the second already the data that I currently bring to the table? - Zarochintsev
- Yes, as an option, there will probably be a lot of code, but it should work well and beautifully, at the same time the problem with the iPhone 3.5 "/ 4" will be solved. PS I generally create a xib + cell for almost every bit of the screen, there is a lot of scribbling, but support and changes are bloodless. - AlexDenisov
- oneTake out a part of your view, for example, in the heading section, the rest of the table — the cells — will be the same as yours now. - AlexDenisov
It seems to me that the easiest and fastest way to solve such problems (at least I do this way) is this:
Throw the table in full screen, in front of the cell insert a view - on which you have buttons / labels, etc. And everything works fine on both 3.5 and 4 inch devices, here's a drawing as an example:
- Thank you very much, I raced for several days in a row with all sorts of functions and other things, and then it turned out so easy and not so difficult, aaaa kapets, I do not believe my eyes that everything works without any functions / autolouats and other crap !!! Thank you, you helped me out so much! - Zarochintsev
- Thank you! And I was tormented! - Beginnerrr
If I understand you correctly,
We implement the UIScrollViewDelegate method. In our UIViewController, when we become a delegate to UITableViewDelegate, we automatically delegate its scroll behavior, since this is a scroll subclass, so in the methods:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.tableView) { // проверка на тот случай, если вы делегируете еще и свой вторй UIScrollView self.mySecondScrollView.contentOffset = self.tableView.contentOffset; // или расчитываем значения если зависимость contentOffset'ов не прямая } }
- Everything works :) Only there is a small joint, it turns out that the table is leaving with all the view, how can I fix it? (I have this hierarchy: I’m looking at the main view ----- I look at the scroll ---------- I’ll see (and it already has a table and all the buttons / labels ...) - Zarochintsev
- You definitely shouldn't put a table on a scroll view, if you can, make view - (table and scroll nearby). In principle, it’s not very clear what you are trying to do there, so it’s a bit difficult to help here - iFreeman
- @iFreeman, look, I have a map on top (mapView) after it comes a row of labels, buttons, then the table itself goes, and you need to scroll all the elements on the view, everything is placed like this: View -> ScrollView -> ContentView (Labels, Buttons, UITableView ) - Zarochintsev
For those who are on hardcore and decided not to do a header on the table - here’s the code to scroll the height for a scroll view:
(void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGSize maximumTableSize = CGSizeMake(self.yourTableView.frame.size.width, FLT_MAX); CGSize expectedTableSize = [self.yourTableView sizeThatFits: maximumTableSize]; //назначаем фрейм с нужной высотой previousFrame = self.yourTableView.frame; newFrame = self.yourTableView.frame; newFrame.size.height = expectedTableSize.height; self.yourTableView.frame = newFrame; //назначаем высоту заднего скролла [self.yourScrollView setContentSize:CGSizeMake(self.yourScrollView.contentSize.width, self.yourScrollView.contentSize.height - previousFrame.size.height + self.yourTableView.frame.size.height )]; }