Rectangle 27 0

In your viewDidScroll: delegate method track the contentOffset for your UITableView. You can then set the UIView's frame accordingly.

iphone - Growing header in UITableView as user pulls - Stack Overflow

iphone ios uitableview
Rectangle 27 0

The simplest way is put your UITextField on UITableView header when UIToolbar button item touched. The simplest way is put your UITextField on UITableView header when UIToolbar button item touched. After user done on UITextField then update your NSMutableArray reload data of UITableView and remove header on UITableView.

uitableview - Adding UITableViewCell with a UITextField upon pressing ...

uitableview nsmutablearray uitextfield uibarbuttonitem
Rectangle 27 0

I recently posted a blog post about accomplishing this using constraints which might help, turns out it was quite straight forward.

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

//_______________________________________________________________________________________________________________
// this represents the display and behaviour of the cells.

@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>

@optional

// Display customization

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

// Variable height support

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

// Section header & footer information. Views are preferred over title should you decide to provide both

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

// Accessories (disclosures). 

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_3_0);
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

// Selection

// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

// Editing

// Allows customization of the editingStyle for a particular cell located at 'indexPath'. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;

// The willBegin/didEnd methods are called whenever the 'editing' property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

// Moving/reordering

// Allows customization of the target row for a particular row as it is being moved/reordered
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;               

// Indentation

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; // return 'depth' of row for hierarchies

@end
//_______________________________________________________________________________________________________________
    // this protocol represents the data model object. as such, it supplies no information about appearance (including the cells)

@protocol UITableViewDataSource<NSObject>

@required

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

@optional

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// Editing

// Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

// Moving/reordering

// Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// Index

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  // tell table which section corresponds to section title/index (e.g. "B",1))

// Data manipulation - insert and delete support

// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

// Data manipulation - reorder / moving support

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

@end

ios - delegate and datasource methods for UITableView - Stack Overflow

ios cocoa-touch uitableview
Rectangle 27 0

I dont know if this would help you or not ..

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;

if (scrollOffset == 0)
{
    // then we are at the top
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
    // then we are at the end
   // Do what you need here 
}

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

First of all you should remove the UIImageView from the header and add it as a simple UIImageView on top of the UITableView then since UITableViewDelegate protocol conforms to UIScrollViewDelegate protocol you can implement the scrollViewDidScroll: method to check when the tableView is scrolling down and has a bouncing effect. something like this:

-(void)someInitMethod {
   initialFrame = yourHeaderView.frame;
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView {
    if(scrollView.contentOffset.y < 0) {
       initialFrame.size.height -= scrollView.contentOffset.y;
       yourHeaderView.frame = initialFrame;
    }
}

Also make sure you set the proper contentMode for your UIImageView. Also I think this implementation will create a bouncing effect but I'm not sure because I can't test it right now but I think this is a good start point for you.

Hey Dany thanks for your time! I have followed your advice and have tried what you recommended. For some reason though, as I drag down, the image just disappears, and never returns. The bouncing effect is implemented which I like though. Any suggestions? I have updated my question to show you what I tried.

Please check the ` initialFrame.size.height -= scrollView.contentOffset.y;` I think there is a + instad of - but I'm not sure. So first check the image view frame in scrollViewDidScroll and after that if everything is correct check if there is a need for setNeedsDisplay on imageView to redraw the image.

The math is incorrect, this would make it look jerky as it keeps adding up to bigger and bigger number instead of increments of the difference.

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

I recently posted a blog post about accomplishing this using constraints which might help, turns out it was quite straight forward.

That is indeed great, but it is of no use for @KingPolycon, as he is using an image at the top of a table view, and in this case it is a lot more tricky to handle - I'm still looking into it myself. Though I guess he either found a way to do it or changed drastically his approach since he posted this question :p.

@CyberDandy You are correct, the table view header view does behave differently

This is the reason one should answers along with links. The link is dead. I'm going to downvote this. It's a 7 upvotes that is worth nothing now. I'll Upvote again when the link is back up or some sort of answer is added.

You're right about posting with links, however if you really need it, here you go: web.archive.org/web/20160326225445/http://

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

I don't know, if this would help you or not ..

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset == 0)
    {
        // then we are at the top
    }
    else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        // then we are at the end
        // Do what you need here 
    }
}

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

Please have a look at this https://github.com/matteogobbi/MGSpotyViewController which implements the same effect as per your requirement.

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

Actually looks like there are a few libraries out there, and using the first table cell is not the way to go. "Parallax" seemed to be the magic google term.

iphone - Growing header in UITableView as user pulls - Stack Overflow

iphone ios uitableview
Rectangle 27 0

You are adding a UISearchController as your UITableView's headerView. Table view headers are not "sticky", and scroll with the cells as the user scrolls through the table. Consider creating a section header and adding your UISearchController there in viewForHeaderInSection.

How to prevent search bar from disappearing on scroll? iOS Swift - Sta...

ios swift uitableview uisearchbar
Rectangle 27 0

This is how I achieved it, in my case I was using a map view up the top:

  • Create a View Controller in storyboard.
  • Add a Table View and set the constraints to 0 from all sides.
  • Add a Map View (or whatever view) below the Table View so that it will get rendered over the top. It will look like it is overlapping.
  • Add constraints to the top left and right.
  • In the view controller viewDidLoad add the following: tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0) where 200 is the height of the View. This will push the contents of the table view downwards.
  • In the view controller add the following code, which resizes the view based on the scrolling: func scrollViewDidScroll(scrollView: UIScrollView) { var scrollOffset = scrollView.contentOffset.y var headerFrame = mapView.frame if (scrollOffset < 0) { // Adjust map headerFrame = CGRect(x: mapView.frame.origin.x, y: mapView.frame.origin.y, width: mapView.frame.size.width, height: -scrollOffset) } else { // Adjust map headerFrame = CGRect(x: mapView.frame.origin.x, y: mapView.frame.origin.y, width: mapView.frame.size.width, height: 0) } mapView.frame = headerFrame }
contentInset

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

First of all you should remove the UIImageView from the header and add it as a simple UIImageView on top of the UITableView then since UITableViewDelegate protocol conforms to UIScrollViewDelegate protocol you can implement the scrollViewDidScroll: method to check when the tableView is scrolling down and has a bouncing effect. something like this:

-(void)someInitMethod {
   initialFrame = yourHeaderView.frame;
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView {
    if(scrollView.contentOffset.y < 0) {
       initialFrame.size.height -= scrollView.contentOffset.y;
       yourHeaderView.frame = initialFrame;
    }
}

Also make sure you set the proper contentMode for your UIImageView. Also I think this implementation will create a bouncing effect but I'm not sure because I can't test it right now but I think this is a good start point for you.

Hey Dany thanks for your time! I have followed your advice and have tried what you recommended. For some reason though, as I drag down, the image just disappears, and never returns. The bouncing effect is implemented which I like though. Any suggestions? I have updated my question to show you what I tried.

Please check the ` initialFrame.size.height -= scrollView.contentOffset.y;` I think there is a + instad of - but I'm not sure. So first check the image view frame in scrollViewDidScroll and after that if everything is correct check if there is a need for setNeedsDisplay on imageView to redraw the image.

The math is incorrect, this would make it look jerky as it keeps adding up to bigger and bigger number instead of increments of the difference.

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview
Rectangle 27 0

I ended up using a plain UITableView with the first cell being a header. The second cell includes a UITextView with it's height dynamically calculated to match the height of the UITextView. The UITextView has scrolling disabled, only leaving the UITableView's scrolling. There's a weird behavior of scrolling as the user taps the text view to edit it, but I don't think that's a major issue

You could also have used tableHeaderView and tableFooterView of the UITableView

objective c - iPhone iOS how to add a visible a header view to UITextV...

iphone objective-c ios header uitextview
Rectangle 27 0

I believe it's a headerView on a UITableView or a UICollectionView, depending on which view mode you have selected. When you tap one of the buttons it changes out the UITableView to a UICollectionView or vice versa.

You want to keep track of the current contentOffset for whichever is being displayed (UICollectionView and UITableView are both subclasses of UIScrollView so you will be able to get this from both) and then set the contentOffset on the view you're switching to.

Setup an ivar for the UIView header subclass so you can easily re-use it.

so what you're saying is that both tableview and collectionview will have the same header and each button's action from the header will have to have the same implementation in each class? in my app I plan to have 4 buttons. Isn't that a bit of overhead?

Honestly it depends on what you're wanting to display in the four different views. You might consider a parentViewController/childViewController implementation if you're going to display several different UITableViews, but you can also try and change out the dataSource for the table views and track which mode you're in to ensure you're getting the correct amount of rows, objects, etc.

ios - uitableview with header like instagram user profile - Stack Over...

ios uitableview uiscrollview instagram
Rectangle 27 0

The earlier solutions on this page gave me some trouble when I needed this to work along with section titles and index bar, so I came up with the following alternative myself. Please note; I don't use autolayout in my project and I've only tested this on iOS9+;

  • Create a UITableView within a UIViewController (or try it with a UITableViewController).
  • Drop a UIView at the top (but within) the UITableView, so it becomes a table header above the first cell.
  • Give this header view a desired height (like 200px for example) and set the background color to "Clear Color". The Clear Color is important, the view needs to be see-through.
  • Drop a 2nd UIView within the table header UIView and make it the same size as it's parent. This will be the actual header, so feel free to give it any color, setup an image view or other content.
- (void)viewDidLoad
{
    [super viewDidLoad];

    // Remove view from table header and place it in the background instead.
    [self.headerView removeFromSuperview];
    UIView *backgroundView = [UIView new];
    [backgroundView addSubview:self.headerView];
    self.tableView.backgroundView = backgroundView;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    /* Set initialScrollOffset ivar to start offset, because in my case
       the scroll offset was affected by the statusbar + navigation bar heights
       and the view controller's "extend edges under top bars" option. */
    initialScrollOffset = self.tableView.contentOffset.y;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    /* Modify headerView height only if the table content gets pulled
       beyond initial offset. */
    if (scrollView.contentOffset.y < initialScrollOffset) {
        CGRect frame = self.headerView.frame;
        frame.size.height = self.tableView.tableHeaderView.frame.size.height + -scrollView.contentOffset.y;
        self.headerView.frame = frame;
    }
}

I needed this implementation only for a stretching header with background color and labels. It should be easy to add a UIImageView to this header though.

Also, steps 1 to 5 are completely optional of course. You can programmatically create your header view or use a XIB instead. As long as you make sure the table has a Clear Colored header view set with the same height as your desired header because this serves as a spacer to keep your cells and section titles in line.

  • Build up your table header in interface builder as described above: 1 UIView as container with a 2nd UIView embedded within.
  • Skip the viewDidLoad code above, there is no need to pull the UIView out of it's container and we won't need to set it as a table background.
scrollViewDidScroll:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
      if (scrollView.contentOffset.y < initialScrollOffset) {
           CGRect frame = self.headerView.frame;
           frame.size.height = self.tableView.tableHeaderView.frame.size.height - scrollView.contentOffset.y;
           frame.origin.y = self.tableView.tableHeaderView.frame.origin.y + scrollView.contentOffset.y;
           self.headerView.frame = frame;
    }
}

That's it. Only visual difference from the other solution is that the contents will now scroll up along with the rest of the cells instead of being overlapped by them.

objective c - iOS: Stretching / Resizing UITableView Header As The Use...

ios objective-c uitableview uiscrollview uiimageview