Custom touch area on tableview cell with checkbox iphone - iphone

I've added a checkbox to a table view cell which is a custom button with two images. Clicking this works fine as I can check and uncheck.
The problem is when you click the rest of the row it still selects the checkbox/button. If I comment out didSelectRowAtIndexPath it doesn't happen so I'm wondering how to get around this happening?
A solution I'd be happy with is to allow only selection of the Accessory Disclosure Indicator but there doesn't seem to be a way of doing this.
Sorry if this is a really badly asked question, I'm very tired! Let me know if you need code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WedAppDelegate *delegate = (WedAppDelegate *)[[UIApplication sharedApplication] delegate];
PlanTaskShowViewController *planTaskShowViewController = [[PlanTaskShowViewController alloc] initWithNibName:#"PlanTaskShowViewController" bundle:nil];
[delegate.navController pushViewController:planTaskShowViewControlleranimated:YES];
[planTaskShowViewController release];
}

put an button on the front instead of an image and do the selecting thing only when button is clicked (change the image of the button).
OR
put an on click event listener / gesture recognizer on your image
UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(changeImage:)];
[imageView addGestureRecognizer:singleFingerDTap];
[singleFingerDTap release];
//EDIT:
If you use highlightedImage for your UIImageView or UIButton it will be highlighted when selecting the UITableViewCell. It's a really nice feature, but sometimes it's only confusing ;)

Check this :
UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(changeImage:)];
[imageView addGestureRecognizer:singleFingerDTap];
[singleFingerDTap release];

Related

Prevent UITableViewCell highlighting when image in content view is touched

I have added a UIImageView to the right side of the content view of my UITableViewCell.
I am trying to prevent the cell from being highlighted while the user is touching the UIImageView (because an attached gesture recognizer performs some other functionality).
I have thought about implementing tableView:shouldHighlightRowAtIndexPath: and returning NO, but I am unsure how to easily determine if the image is being touched when this method is called. Is there an easy way to do this?
Try this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// Add tap gesture recogniser to cell's image view
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped)];
tap.cancelsTouchesInView = YES;
cell.theImageView.userInteractionEnabled = YES;
[cell.theImageView addGestureRecognizer:tap];
return cell;
}
The important parts are to make sure the image view has userInteractionEnabled = YES and the gesture recogniser has cancelsTouchesInView = YES.
This will cause the tapped method to fire if the image view is tapped, but the cell will not be highlighted.
why don't you add a UIButton with type custom.Will have the tap button action.Will not affect the cell highlight
Prevent highlight of tablecell
cell.selectionStyle = UITableViewCellSelectionStyleNone;
or
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Labels with targets to another view

I would like to have a login similar to this screenshot:
The problem is that I don't know how to do the bottom, these two options. When I push, I'd like to put another view — the sign up view or reset password view —, but I don't know how to do these elements (are they labels?).
They could be UIButton with the type Custom and with a value for the text:
To make this, First you take a UILabel to show the "Tumblr" option. Then you create a UITableView. This TableView would contain 2 sections like "Email" and "Password". Make the edges of the UITableView as rounded using
TableView.layer.cornerRadius = 10;
Now to push to another view you can simply write any data in the UITableViewCells in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
and using the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you can pass that information to the next view for the reset password option you mentioned likewise. Create a UIButton and name it as "Login".
I this is what you wanted to achieve ?? Any doubts please tell. Thanks :)
EDIT:
For the options below what you can do is that make the UIButtons as custom and write their text as "Reset Password" etc. Then on their click you can open a presentModalViewController of each of the next view's or in the same view itself, in which you would be able to do your sign in and reset stuff. Hope it helps !!!
It is a label and you link it with the action method.
//using UITapGestureRecognizer to easy to set target to another view
UITapGestureRecognizer *tab_1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(action_1)];
tab_1.delegate = self;
[label1 addGestureRecognizer: tab_1];
UITapGestureRecognizer *tab_2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(action_2)];
tab_2.delegate = self;
[label2 addGestureRecognizer: tab_2];
-(void)action_1{
//your action or view;
}
-(void)action_2{
//your action or view;
}

How to pause/disable UILongPressGestureRecognizer on a UITableViewCell while in editmode

In a tableview I have on every cell a UILongPressGestureRecognizer which I add like this:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(TableCellLongPressed:)];
longPress.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:longPress];
[longPress release];
Now I do have the following problem I want the user to be able to rearrange the cell in the tableview so I have a button that sets the tableView to EditMode like this:
[self.myTableView setEditing:!self.myTableView.editing animated:YES];
Now when the user tries to drag a cell and does not drag it far enough the longPress fires his action which is very annoying for the user cause another view gets pushed.
How can I pause or disable the UILongPressGestureRecognizer when the tableView is in EditMode?
You should implement the UIGestureRecognizerDelegate delegate for this method:
gestureRecognizer:shouldReceiveTouch:
In the method, check if you're editing the table and return NO if you are.
Tim

how is a drop-down list made on the iphone?

I want for a given label Example: Typemarital (possible answers: married, single, PACS, divorced, etc ...) to choose from a predefined list and know how to freeze the answers to a user on a field and not a view (without using the builder interface ) just through the code .
Thanks
It can be made using a button and and a picker view.
1) On click of button, you have to show the picker view and from picker you have to select the value you want. Then from inputAccessoryView of picker view in which you can add a toolbar with done button.
2) On done button click you can get selected value of the picker and hide the picker.
3) The selected value then you can show it into a UILabel.
Hope this helps you.
EDIT:
Here is a very useful tutorial for dropdownmenu in iPhone/iPad:
http://kshitizghimire.com.np/dropdown-in-iphoneipad/
Its quite simple actually.
On click of label create a view and inside it create a table view where you can display list you require, and by simply clicking on cell i.e.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
place text of selected cell to your label and remove your view.
Hope it helps.....
you have to use UITableView.
1) Create a button with title.
2) when clicked on button tableView will be shown.
3) when one of the row of tableview would selected the tableview goes hide and the button title would be row selected in tableview..
You can use UIActionSheet. Add UIPickerView in UIActionSheet.
On tap of a button Try this:
category = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
category.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView *categoryPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,50, 320, 120)];
categoryPicker.delegate = self;
categoryPicker.dataSource = self;
categoryPicker.showsSelectionIndicator = YES;
[categoryPicker selectRow:1 inComponent:0 animated:NO];
[category addSubview:categoryPicker];
UISegmentedControl *segmentedControlDone = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
segmentedControlDone.momentary = YES;
segmentedControlDone.frame = CGRectMake(260, 7, 50, 30);
segmentedControlDone.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControlDone.tintColor = [UIColor blackColor];
[segmentedControlDone addTarget:self action:#selector(actionPickerDone) forControlEvents:UIControlEventValueChanged];
[category addSubview:segmentedControlDone];
// implement data source method of UIPicker also

How to make a uiactionsheet dismiss when you tap outside eg above it?

How do i make a uiactionsheet dismiss when you tap outside eg above it? This is for iPhone. Apparently the ipad does this by default (I may be wrong).
Ok got a solution. The following applies to a subclass of a UIActionSheet
// For detecting taps outside of the alert view
-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self];
if (p.y < 0) { // They tapped outside
[self dismissWithClickedButtonIndex:0 animated:YES];
}
}
-(void) showFromTabBar:(UITabBar *)view {
[super showFromTabBar:view];
// Capture taps outside the bounds of this alert view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapOut:)];
tap.cancelsTouchesInView = NO; // So that legit taps on the table bubble up to the tableview
[self.superview addGestureRecognizer:tap];
[tap release];
}
The gist of it is to add a gesture recogniser to the action sheet's superview, and test all taps to see if they are above the action sheet.
it may be useful to you
Use:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
previous so question
I think you are looking for this method
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
EDIT
you can use this on your action sheet object and it works just fine but you cannot register event outside that sheet like the grayed out part
may be if you use UITapGestureRecognizer on your view controller than it might do the trick.
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(nothing)];
[actionSheet addGestureRecognizer:recognizer];
After setting the cancelButtonIndex property of UIActionSheet with a valid value, tapping outside will dismiss the UIActionSheet. I have tried in iOS 9. However, if this cancelButtonIndex is not set of set to a wrong value (e.g. an index beyond the total button count in the UIActionSheet), nothing will happen when tapping outside.
No need of any tap gesture. Simply use UIAlertActionStyleCancel action.
You can't do that by tapping outside because action sheet covers whole view some transparent black view with buttons in form of sheet in iphones but in ipad this behavior presents by default .
so for touching outside you cant call touch methods. so i don't think so you can do in this way and also when apple provide a cancel button in action sheet then why not you do use that button rather than this.
This does not answer the question exactly, but here is what I do to close the picker when clicking on one of its items (this prevents from adding additional "done" button or "outside click" stuff):
Implement the viewForRow picker's delegate method in which you create a UILabel and return it:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
On those custom row labels, add a tap action handler:
UITapGestureRecognizer *tapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleClick:)];
[label addGestureRecognizer:tapAction];
In the handleClick callback, dismiss the open sheet (the one that contains the picker view):
[pickerSheet dismissWithClickedButtonIndex:0 animated:TRUE];
Use showFromRect, for example:
UIView *barButtonView = [barButtonItem valueForKey:#"view"];
CGRect buttonRect = barButtonView.frame;
[actionSheet showFromRect:buttonRect inView:self.view animated:YES];
in iOS7 I add dismissWithClickedButtonIndex msg in gestureRecognizerShouldBegin, and it works.
Use .cancel UIAlertActionStyle as an option.
Just add an alert with style: .cancel. Rest of the work will be done automatically.
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))