iPhone - Custom UITableViewCell with clickable UITextView - iphone

I created a custom UITableViewCell and placed a UITextView element on it. Now when I click on the UITextView inside the cell tableView:didSelectRowAtIndexPath: is not called (in the superview which is a UITableViewController).
Should I make the UITextView "transparent" or something? How can I do that? I get the same effect when adding a button.

Adjust the userInteractionEnabled property to NO
someTextView.userInteractionEnabled = NO;
Documentation here: http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/userInteractionEnabled
Similar question here: iOS: Selecting through UITextView on custom UITableViewCell

Related

how to slide UILabel in uitableviewcell when swipe to delete is used

I have a custom uitableview with a UILabel to the right of the cell as shown below
I have enabled swipe to delete, but when the button appears the UILabel is covered, I am guessing this is because my custom tableviewcell has not been informed about the delete button..
I am wondering how I go about moving the UILabel to the left of the delete button when the swipe is detected.
This is how you would do it if you create the cell in a xib.
You create a view the same size as the cell and put all of your labels inside it. Create an outlet for this view. Then in the .m of the customCell you add the view to the contentView.
[[self contentView] addSubview:cellView];
Then, in the xib add struts so that the labels stick to the edge of whatever side they are nearest and you should be good to go!

UITextView in custom UITableViewCell not responding to didSelectRowAtIndexPath

I have a UITextView in my custom UITableViewCell and the issue is that when I tap on it it won't respond to the didSelectRowAtIndexPath or even swipe events. How can I fix this? This UITextView is not editable. The reason why I use this over a UITextField is because I want to be able to detect links easily.
I realize this is an old question, but I recently had the same issue. The fix in my case was to simply turn off "User Interaction Enabled" for the UITextView.
you need to forward the touch messages from UITableView to UITextView
UITextView inside UITableView
The first idea that came to mind...
In cellForRow set the textfield tag as the indexpath.row
Implement - (void)textViewDidBeginEditing:(UITextView *)textView
Based on this textView.tag, call the selectrow
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:textView.tag inSection:<#(NSUInteger)#>]
animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>]
I don't know if it's what are you looking for But in my case i had a custom cell with UIImage, and UITextView and only when I clicked on UIImageView i got didSelectRowAtIndexPath recogniser. Make sure UITextView is user interections unable like that to fix the problem
Check if your TableView Selection property is set to NO
Wrong :
tableView.allowsSelection = false
DidSelect Wont be called
It has to be:
tableView.allowsSelection = true
Also Check your Nib

Another Button at UITableView Editing Mode

I need an additional button next to the Delete button when in editing mode of UITableView Cells. Any suggestions for the purpose is appreciated. Thank You.
I would suggest you first subclass UITableViewCell. In the respective init method you create the button and add it to the contentView as a subview. Make the button hidden. After that you overwrite layoutSubviews and position the button on your content view by setting the frame property of the button. Then also subclass willTransitionToState: and check if the state is UITableViewCellStateShowingEditControlMask. If that's the case make the button visible. If not hide it.
Note: If you add an additional button to the UITableViewCell you also need to adjust the textLabel frame and other stuff to not overlap the button's rectangle.
cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
or some other value than "check"
or
cell.editingAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoDark];
or with some other value than the info button, with it's target set to something appropriate
an accessory view trumps a type

Determine whether UITableViewCell is editing from "swipe" or "self.editButton"

I'm trying to determine whether a UITableViewCell subclass is in edit mode from a user's swipe (in which case I don't need to indent my subviews) or from the user pressing the "Edit" button associated with the UITableViewController. (In which case I do.)
I know it's possible from a cell's perspective, since the self.textLabel view automatically indents properly. I have tried:
-(void)layoutSubviews {
[super layoutSubviews];
CGRect labelFrame = self.textLabel.frame;
labelFrame.origin.x += 5;
myCustomUILabel.frame = labelFrame;
}
But my custom label does not properly indent. (Though the self.textLabel view does?)
I would like to avoid the following:
Providing the cells with a reference to the parent table.
Overriding methods in the UITableViewController class to let the cells know whether they are being edited individually or the entire table is editing.
You can override willTransitionToState: in your UITableViewCell subclass. When the "Edit" button is pressed the state will be UITableViewCellStateShowingEditControlMask(=1) and when swiping it will be UITableViewCellStateShowingDeleteConfirmationMask(=2).
You should not be doing the indentation manually. The UITableViewCell will do it for you!
All you have to do is make sure that you add your subviews to 'contentView' of the UITableViewCell. This is the reason why self.textLabel indents properly as you have identified.
Look at the documentation of contentView property for a UITableViewCell:
The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

UITableViewCell's detaiTextLabel overlaps with custom subviews

I want to customize UITableViewCell by adding UILabel and two UIButton as its subview.
The cell style will be UITableViewCellStyleSubtitle and these three items would have to
next (on the left) of detailTextLabel.But when i do this, detailTextLabel overlaps with these items and display clipped or partial subviews.
Any way to handle out this without subclassing UITableViewCell if possible.
Thanks.
do you want to display something with detailTextLabel? If not you could try to hide it.
cell.detailTextLabel.hidden = YES;
otherwise you could add another Label at a better position which displays your detailText