iOS tableFooterView: Can't use UIButton? - iphone

I made a custom UIViewController with an UIImageView and a UIButton in it. In the tableView viewForFooterInSection method I returned the view, and it displays correctly(i can see the button). However, I can't touch the button. It won't depress/highlight, and my connected IBAction doesn't fire.
Also, I have an object from the camera called takenPicture. myImage is a UIImageView IBOutlet property of customView. The imageView is always empty.
I'm not sure what I'm doing wrong, but here is my code that is in the viewForFooterInSection method:
self.customView = [[CustomView alloc] initWithNibName:#"CustomView" bundle:nil];
customView.myImage.image = self.takenPicture;
return customView.view;

It sounds as if the frame/bounds isn't set correctly for your view (the one containing the button and image view). Likely it is defaulted with CGRectZero, and the reason you can see the button and image is because clipping is off. But touch events wont filter up to the button if it is outside the bounds of its superview.

Related

UIImageView still visible after hiding/removing from superview

i hope you will find a solution for my problem, cause i don't have any ideas anymore.
I have a tableview, which has several cells. some cells have another view as subview on their contentView.
This additional view has 2 subviews: 1 UIImageView and 1 UILabel.
Now when i tap an UIButton the UIImageView should be hidden/removed and the UILabel changes it's textColor to white(black before).
The UILabel changes it's textColor but the UIImageView is still visible, even after removing the UIImageView from it's superview.
The Code looks like this.
_adsc_dot_view is the UIImageView
_adsc_text_label is the UILabel
- (void)mc_set_selected:(BOOL)selected {
if (selected) {
_adsc_dot_view.hidden = YES;
_adsc_text_label.textColor = [UIColor whiteColor];
}
else {
_adsc_dot_view.hidden = NO;
_adsc_text_label.textColor = [UIColor blackColor];
}
}
Some check you might find useful for this issue:
1) make sure you create once your UIImageView which referenced as _adsc_dot_view
2) do a debug, mark mc_set_selected with a breakpoint and in the log check the view hierarchy, whether you have the needed number of UIImageView and not more
po [[UIWindow keyWindow] recursiveDescription]
or check this advanced SO answer: I need to inspect the view hierarchy on an iPhone program
3) if you use Interface Builder make sure you have proper type (and not UIImage) and proper reference
You are using UITableView and you add UIImageView and UILabel as a subview in UITableViewCell. So, I think you should reload UITabeView using [self.tableView reloadData]; or [YourTableName reloadData]; after your hide and show UIImageView method. Otherwise you should hide and show UIImageView using UIImageView tag or using UITableViewCell index path.
is the target device on iOS 7? If yes then do try to layoutsubviews of the cell. I had a similar issue where the cell wasn't refreshing on ios 7.
Just reload table view cell after Remove/Hide ImageView.

presentPopoverFromRect from a button goes out of bounds

So I am using WEPopover to display a custom view controller pop up. I have a UIView in which inside it has another UIView called containerView. Inside this containerView, I have a UIButton. This is where I wanted to present my popover from. So here's what I did:
[self.popoverDialog presentPopoverFromRect:sender.frame inView:self.containerView permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
The issue is that the arrow and everything is showing from this button, but the popover goes out of self.containerView bounds. How can I make it so that the popover is displayed within the containerView bounds?
EDIT:
A picture is worth a thousand words, so here it is:
The light gray is the containerView I mentioned above. THe popover theoretically should be shown within that light gray bounds not going outside.
For the view that is contained inside the popover, go to it's view controller and set it's property contentSizeForViewInPopover. Here you can set the size so that it fits the bounds of your containerView.
OP wants to position the popover so that it only shows up in his container view. I found this bit of code in the WEPopoverController.m file
- (void)repositionPopoverFromRect:(CGRect)rect
inView:(UIView *)theView
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections {
CGRect displayArea = [self displayAreaForView:theView];
WEPopoverContainerView *containerView = (WEPopoverContainerView *)self.view;
[containerView updatePositionWithAnchorRect:rect
displayArea:displayArea
permittedArrowDirections:arrowDirections];
popoverArrowDirection = containerView.arrowDirection;
containerView.frame = [theView convertRect:containerView.frame toView:backgroundView];
}
You could possibly call this method and it might reposition your popover so that it is now inside your container viw.

Which button state is triggered when you long-click (highlight) the cell in which it exists?

I have a custom table view cell view that contains a button. I initialize the button to setBackgroundImage to an empty circle in its normal state. I also setImage to a checkmark image for its selected state.
checkmarkButton = [[UIButton alloc] initWithFrame:CGRectMake(kLeftMargin, kTopMargin, kButtonSize, kButtonSize)];
[checkmarkButton setBackgroundImage:[UIImage imageNamed:#"empty-circle.png"] forState:UIControlStateNormal];
[checkmarkButton setImage:[UIImage imageNamed:#"checkmark.png"] forState:UIControlStateSelected];
[checkmarkButton addTarget:self action:#selector(checkmarkButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:checkmarkButton];
When the button is clicked on, I set the button as selected and told to redraw so that the button looks like a circle with a checkmark in it. Click on it again and selected is set to NO and the cell is told to redraw so that it's an empty circle.
- (void)checkmarkButtonPressed:(id)sender
{
[checkmarkButton setSelected:!checkmarkButton.selected];
[managedObjectContext save:nil];
}
My problem is that this button exists in a custom table view cell view, which seems to control how it's drawn in a way that I can't identify. When I long-click (touch down in the cell and staying in the cell without touching up for a while) on a cell whose button is set selected (should display a checkmark in a circle), the checkmark disappears until I touch up. When I touch up, the state of the cell is correct. It's just wrong while I am long-clicking the cell.
So, how do I control how that button is drawn when I long-click on the cell?
I'm not sure if this is exactly your case because I didn't see your sources. But please check the Highlighted state of your button. When UIButton is placed on UITableViewCell then table controls your UIButton: on cell touch down (long touch) UIButton as well as UITableViewCell change its state to Highlighted and returns to Default or Selected state on touch up.
UPDATE:
I agree it is unexpected behavior. You can create subclass of UIButton and reimplement this call to leave it empty to prevent calling super method:
- (void)setHighlighted:(BOOL)highlighted;
Example:
#interface XButton : UIButton
#end
#implementation XButton
- (void)setHighlighted:(BOOL)highlighted { }
#end
This should prevent state changing by table.
when you click and hold a button the state that is getting called is the highlighted state, thus when you release the click the state returns to UIControlStateNormal

How do I get the position of a txtfield inside a popoverview with respect to ipad screen

I have a UITextfield in a tableview in a view controller, and I am displaying this view in a UIPopOverView. I wanted to know how can I get to know the position of the textfield with respect to IPAD screen...so that i can move my tableview upwards on Textfield editingDidBegan
Try using the convertPoint:toView: or convertRect:toView: methods of UIView.
So for example, to get the textField's bounds relative to the window, say
CGRect *bounds = [textField convertRect:textField.bounds toView:window];

Setting the alpha of the table with a transparent subview to a UITableView

I have added a subview over my UITableView using:
TransparentViewController *tvc =
[[TransparentViewController alloc]
initWithNibName:#"TransparentViewController" bundle:nil];
[self.view addSubview:tvc.view];
My Nib has a UIImageView in it that has some text and a transparent background.
When I load the detailView for the table for the first time I show the subview that gives a brief explanation of the information that you can see below the text. Works really well.
What i would like to do is alter the alpha of the underlying table so that it is dimmer but not affect the alpha of the overlay subview. If i use:
[self.view setAlpha:(CGFloat)];
It dims the overlay as well. I seem to be having a mental block.
Changing the alpha affects the subviews as well. Your tvc.view is a subview of self.view, so it is naturally going to be affected.
Why don't you try this: put another view in tvc.view and send this view to this view to the back.
(UIView*) back = [[UIView alloc] initWithFrame:CGFrameMake(...)];
back.backgroundColor = [UIColor grayColor]; // choose a color that you like;
back.alpha = 0.5; // whatever works for you
[tvc.view addSubview:back];
[tvc.view sendSubviewToBack:back];
Set the size and alpha of this new view to something you like. The table view will show through it to a limited extent, which may accomplish what you are trying to do.
Since this is part of our tvc view, it will appear when you show that view and go away when you hide that view.