Avoid cell autoresizing in editing mode iPhone - iphone

I have a problem with my custom cells.
My cell is structured like this image:
Gray view = cell.contentView
Orange view = a button added as a subview to the contentView
Yellow view = a label added as subview to the contentView
Blue view = an image view added as subview to the contentView
Green view = accessory view
The problem is that when I toggle edit to tableView, my cell indents hiding accessory view and moving right everything else. I want to avoid this.
When I toggle editing mode, my cell mustn't move its content, the editing control (minus red button on the left) must take the place of the button inside the contentView and this last one should hide itself.
I tried tableView:shouldIndentWhileEditingRowAtIndexPath: method without success because my tableView is plain. I also tried to override willTransitionToState: method but I don't know how to do what I want.
Can someone help me?
Thank you so much!

How have you added the subviews to the cell? If you add them directly to the cell instead of adding them to the content view, they won't get moved. It is the content view that is resized when the cell transitions to editing mode.
If you want to hide certain subviews, you should override setEditing:animated: in the cell subclass and hide / show as appropriate.
You may also need to add your subviews such that they are below the contentView in the view hierarchy, or bring the content view to the top after you have finished, using the bringSubviewToFront: method.

If you really don’t want the cell to resize, you could implement -layoutSubviews thusly:
-(void)layoutSubviews
{
if ([self isEditing] == NO) {
// Lay out subviews normally.
}
}
When you go into edit mode, -layoutSubviews won’t follow the code path that lays out your views. This is assuming you’ve subclassed UITableViewCell.

Related

how to add accessoryType to subview of tableviewcell

I would like to know how to set an accessory type, like a disclosure to the subview of a UITableViewCell?
I know how to do this with a activity indicator, but not sure how to do it with a disclosure button?... anyhelp would be great.
This is how I do the activity indicator at the moment.. then when i want to use it I just call start or stop animating.
cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
// Position the spinner
[cellActivityIndicator setCenter:CGPointMake(280.0, 24.0)];
// Add to button
[cell addSubview:cellActivityIndicator];
This is what is happening when the disclosure indicator appears on the right of the uitableviewcell, it is pushing the label out to the left... (label currently has "empty" in it)
This is what happens when I have auto resizing and try to use swipe to delete
You are going about this wrong, you should add your custom subviews like this:
[cell.contentView addSubview:cellActivityIndicator];
The cell content view is resized to take into account accessory views, so any subviews that you have added will be shifted into the correct place (assuming you have sized them correctly and have the right autoresizingMask flags).

View elements resize problem

I have a UiView which contains a UiWebview, UIButton and a UITextView as its elements.
I add this UiView to a UIScrollView and resize the frame so that the text view is not visible. When i click the button i resize the view to display the entire UIView including the UItextview.
The problem is , the text view appears below the view when i resize the frame. When i click expand it covers the text view too.
When view is first added i want the view to display just the webview and the button and when button is pressed it should display the text view.
How do i achieve it? Has it got to do with view hierachy?
you should enable clipping on the UIView .
edit:
I wouldn't resize the view. Instead I would just change the hidden-property on the textview. If you want to add some animations later then you can modify the alpha-property as well.

label and scroll view

HI FRIENDS..
I use a scroll view and a label now i want that when i scroll that , label also scroll with that and set to next location , i set paging enable = YES , so i want that there are 5 images and when i did scrolling the label i set is also move and show in other position.
thanks
To scroll a UILabel (or anything for that matter) WITH a UIScrollView, simply add the label to the UIScrollView.
You can easily do this in Interface Builder by the obvious methods.
You can also do this programmatically by utilizing the addSubview: method.
You can do one thing you change frame of label when you scroll in delegate method of scrollview or you can also make 5 same label in all 5 pages.
Good Luck
Well if you have added a scrollview on top of a uiview you can add that label on the view and then bring it to front. then you dont have to worry about changing frame of the uilabel as it will be always on top of the scrollview and at the same position and also you can change the text of that label when the user scrolls in pagecontrol value changed method.

iPhone UIScrollview: Button does not respond when located below 480 pixels on Scroll View's child UIView

I have built a view for an iPhone app in Interface Builder. It is a UIScrollview with a UIView and a UIButton on the UIView. The only code I have is setting the scroll view's contentSize to 320x550 in the viewDidLoad method of the xib's File Owner class. When the button is within the normal view area (320x480) the button responds as normal, but if is placed outside of those boundaries in Interface Builder the button will not respond when I scroll to it and click the button.
What am I missing? I figure it might be something I need to set on the UIView. But I am not sure what that is.
Your UIButton won't response even it's visible because it's not in the boundary of parent view. You can see object outside the boundary of its parent view because it's a default behavior of UIView to draw all subview (clipsToBounds = NO)
To see the truth, try this code.
UIView *yourUIView = ...
yourUIView.clipsToBounds = YES;
yourUIView.backgroundColor = [UIColor cyanColor];
You will no longer see your UIButton.
To fix this, enlarge your UIView.
I had the same problem as the person who posted the question. Thanks to the first answer, I had a hint as to what to do. I increased the height of the view by adjusting the frame. This, apparently must be done in code. Once this was done, however, the toolbar at the bottom was no longer visible. So before I adjust the height of the view, I grab the position of the tool bar. Then after adjusting the height of the view, I reset the position of the tool bar. Now all is good.

Anchor a UIView

I have a UITableViewController inside of a UINavigationController.
I want to have a UIView appear over the top of the table view but not susceptible to the scrolling of the table view.
I.e. if the table view is scrolled, the UIView should remain in the same position relative to the screen, rather than relative to the table view. It should appear anchored in a certain position.
What is the best way to achieve this?
EDIT: To clarify, the view should float transparently over the top of the table view.
Many thanks!
I also wanted to have a floating UIView over my tableView.
So, within my RootViewController (which is a UITableViewController), this worked for me
- (void)viewDidLoad {
/* mylabel is a UILabel set in this class */
[self.mylabel setUserInteractionEnabled:NO];
/* navigationController comes from higher up in the navigation chain */
[self.navigationController.view addSubview:self.mylabel];
}
Similar to what Peter said, create a UIView that will contain both the TableView and the subclassed UIView. Such as:
UIView *view = [[UIView alloc] initWithFrame:frame]; // Define frame as you like
[view addSubview:myTableView]; // This is the reference to your tableView
[view addSubview:myAnchoredView]; // This is the reference to your UIView "floating" subclass
You will also need to turn off user interaction for your floating view. I don't know if this will specifically pass the touches to the underlying UIView's or not though:
[myAnchoredView setUserInteractionEnabled:NO];
If this is blocking touches to your tableView, you may need to pass the reference to your tableView to the anchored view at initialization, then pass the touch events along. You can do this by overriding the touch response methods in UIResponder. (If there is a better way, someone please speak up.)
Do you mean the anchored view should appear transparent over the UITableView, or just above, i.e. anchored view uses top 20% of the available space, table view uses the rest?
In any case, create a UIView containing the anchored view and the table view. If you want the anchored view transparent over the table view, it's a bit tricky, because to scroll the table view, touches have to pass through the anchored view.
Add the surrounding view's view controller to the navigation controller instead of just the tableview.
I investigated how UIScrollView keeps its scrollIndicator above the UIScrollView's content and yet unmoving by examining a UIScrollView in the debugger.
The scrollIndicators are UIImageViews. And you can see they are direct descendants of the UIScrollView itself. You can also see that any scrolled content is also a direct descendent. So how is it that the scroll indicators don't move?
I tried updating the position of my static content constantly in - (void)scrollViewDidScroll:(UIScrollView *)scrollView this, surprisingly, works. I'm not sure if it is how UIScrollView itself does it, but without some private magic, it must be something like this.