How to have an UI component scrolling with my UITableView - cocoa-touch

I am trying to have a UI component stuck to my cells in a UITableView and scrolling with them...
It seems weird but a picture permits to understand the main point:
Before Scrolling
During Scroll
I am trying to do the same effect but with other UI components (another UIVIew).
Do you have some hints to do this ?
Is it a custom uitableviewcell inserted at start ?
Is there an easy-to-implement hack ?
Thanks a lot for your help !

You can add any UIView and make it scroll with the table cells by placing the UIView in the table header. There is a special property for a table view, called tableHeaderView.
Use something like this:
UIView* my_custom_view;
// TODO: Alloc, and initialize the view
tableView.tableHeaderView = my_custom_view;

Related

Swift: Programmatically set a view before first line of UICollectionViewController

a bit confused reading in the Apple documentation, tried multiple settings but no luck so far, so I hope to have a response here.
I am implementing a UICollectionViewController with header and vertical scrolling.
All work flawlessy but now I want to add a view in which I want to put an TabBar below the header and before the first line of the collectionview.
I want also that the tabBar moves when scrolling so i can't just add a subview and let it disapper once the scroll starts.
I suppose I have to set the spacing for the first line to be big enough and once done create a view, add the subview and create the tabbar inside of it.
Now the question , which sections of those I have to override? https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout
Thanks.
A better approach will be to implement the view to be added as the first cell of collection view.

Custom scrolling drawing layer over UITableView

I've been struggling with this issue for days, so I hope someone can help me out...
I have a grouped UITableView with several cells. I want to draw some custom graphics above the UITableView that would scroll with the content of the table. Specifically, I want to draw a line with dots, joining the UITableViewCells (across the sections) like this:
Of course if we have more cells than what the screen is capable of displaying, the upper layer with the custom drawing should move with the underlaying cells.
I've tried to subclass UITableView and override it's -drawRect method, but it didn't work. Even if I wouldn't call [super drawRect:rect], the table content displayed without problem.
I've tried to add a new subview to the UITableView, but it changes it's size dynamically when it gets the cells and sections from its datasource... I'm out of ideas...
Although the Web is full of custom UITableViewCell samples, I haven't managed to find anything similiar to my concept...
Can anyone help me how to achieve the above mentioned feature?
First your should subclass UITableView. Then create another UIView and add it as a subView of your custom UITableVIew.
Next override the contentOffset property of the UITableView.
-(void)setContentOffset:(CGPoint)contentOffset
{
[super setContentOffset:contentOffset];
// Custom code here. Update custom subview here.
}
This method will be called as the UITableView is scrolled. You can then adjust the offset of your subview and update its drawing.

Custom Table in UIViewController Objective-C

I want to create table view inside of UIViewController like a below picture (I mean the second screen)
what is the best solution? "creating UIViewController then tableView and inside of tableView having custom cell"?
would you please give me some hint?
Thanks in advance!
So basically you want the tableview to not fill up the entire space. Yes, you can surely do UIViewController, let it implement UITableViewDelegate and UITableViewDataSource protocols, throw in a tableview and hook up the protocols, and use custom cells.
If you only want the tableview to not fill up the space horizontally (but it can still scroll all the way until it reaches your navbar), then you can just create a UITableViewController, and set up your cell background in the way you want. More specifically, you create 640px (or 320px) wide background images still, but only the central 600px, say, is filled in. The 20px to the right and left are transparent. (You need png to do this, of course) If you apply this background to your cells and apply another background to your self.view, then you can actually see your view background under the 20px on the two sides.
Note that if you choose the second approach, the cells are still full width; it's just that you are visually making them look like narrower. That's perfectly ok, but you need to customize your highlight background, too.
Looking at your picture, it seems you need to create UINavigation Controller as your parent view controller and add UITabBarViewController as its rootview. then in your second tab when your click on the cell inside the table, you pushview to another view which displays your picture
create a tab bar controller project. Every tabbar item will be a navigation controller.
Tat way u can manage both the navigation and tabs.

Combined UITableView with other elements - how to create and use the view?

Ive a project close to doing everything I need it to do. Its got a Main page which has four buttons that allow you to choose an option. Then a tableview page is launched from those options and displays a parsed XML feed from a website. You can then select one of the options in the table to see a detail view of the item, enquire about it, etc.
My problem is I need to add more elements to the TableViewController page, other than the tableview itself. I want a customized back button (not the navigation controller standard) plus some labels, images, etc.
In the TableViewController xib, the tableview itself fills the page. I cant resize it to add more elements above it. I can add a 'view' window seemingly above the tableview and put things in it. But it seems to add the view to the tableview. This means that when I scroll the table, the other elements like new back button, scroll away as part of the table.
So I'm led to wonder whether I need this page not to be a tableviewcontroller, but a viewcontroller, with a tableview inside it, as well as my other view with buttons, etc. Is that the right way to go? But if thats the case, then how do I instantiate the tableviewcontroller within code? Because my page will not be of that type anymore - it will be just a viewcontroller. But in code Im making a tableviewcontroller .. slightly scared by that route tbh.
Any illumination on this would be much appreciated, as various searches have left me none the wiser. Thanks.
To customize it, this is the way to go:
Change your class to be a view controller instead, which implements the TableViewDelegate and TableViewData Source protocols.
In the view didLoad of you controller, create the table view, set its delegate, data source, and any other properties you wish and add it as a subview to your view.
tableView = [[[UITableView alloc] init] autorelease];
tableView.delegate = self;
tableView.dataSource = self;
// .. Other customization
[self.view addSubview:tableView];
I suggest doing this programatically rather than IB.
Instead of a UITableViewController, you want a UIViewController that has an IBOutlet UITableView. Drag and drop a UITableView component from Storyboard and hook it up, and position it as needed on the screen. This UIViewController should implement the UITableViewDelegate and UITableViewDataSource methods.
Edit: Remember that a UITableViewController is just a subclass of UIViewController so you don't really have to get rid of all your code. :) You only need to make minor tweaks to your header and main file, and change the Storyboard to be a UIViewController instead of UITableViewController as I mentioned above.

UITableView in a UIScrollView - How to make the view scroll, but not the TableView in itself?

Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:
I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?
Possible solutions I've founded today
1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)
2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?
I would ditch the UIScrollView and just use a UITableView. You can add a UIView object as the tableHeaderView of the UITableView just by dragging it in in Interface Builder. Now since everything is part of the UITableView hierarchy, everything will scroll together as expected.
You could also try setting delaysContentTouches to NO on your scrollView. Depending on your setup, this may make the scroll view respond to the touch first instead of the table view.
From Apples UIScrollView Docs:
delaysContentTouches
A Boolean value that determines whether the scroll view delays the
handling of touch-down gestures.
#property(nonatomic) BOOL delaysContentTouches
Discussion
If the value of this property is YES, the scroll view delays handling
the touch-down gesture until it can determine if scrolling is the
intent. If the value is NO , the scroll view immediately calls
touchesShouldBegin:withEvent:inContentView:. The default
value is YES.
You'll have to (as you've mentioned) add the UIView containing the image and buttons to the actual UITableView. Embedding it in the scroll view will produce the undesired behavior that you're seeing.
I would recommend returning the UIView as the header view for the first section of your table view. You can do this by implementing the UITableViewDelegate method:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
If you maintain an IBOutlet to the view containing your image/labels, you can return it here.
this is same demo i hope its helps you from iphone sorce code library
http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html
thank you