Disable cell but leave detail accessory active - ios7

I'm populating UITableViewController with data and some of created cells need to be disabled and some other are left with detail accessory button. What I need to get done is to disable those with detail accessory (their selection) but leave this detail button active to get some info.

Expanding on the answer given by mobiletest, I have done something similar.
I created the cells with the disclosure indicator type for the accessory
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
In the UITableViewControllerDelegate method
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath
I created a custom button on each cell. In order to identify exactly which button on which cell is selected, this answer on SO helped me.
You can choose not to change the selectionStyle of the cell, but I suggest you do, so that the app looks better, and the cell will not show anything to suggest that the cell can be selected, which will make it easier in terms of usability for the user.
Alternatively, you can have a check in the method
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath
You can get the cell selected and check the accessoryType of the cell and place your logic.
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryDisclosureIndicator)
{
//Your logic here
}
But this will mean that your entire cell is made to selectable (if not the disclosure button will not work if selected), and in this case it will mean that you cannot customize your disclosure button. Also, since your entire cell is selectable, your logic will also run as long as the user clicks on the cell, which, judging from the question, does not sound like the feature you want, but I may be wrong. :)
See which works for you. Hope this helps!

Do you want to hide the detail accessory button from some of the rows or disable the functionality where there is no detail accessory button.
To disable the functionality you can have code in didSelectRowAtIndexPath. Check if there is detail accessory button, if there is any then don't do anything.

Related

iOS animate partial cells to show full cell

I've got an UITableViewCell with a UITextField in it. When I click the UITextField I want to make sure the entire cell is visible in the tableView. I did this in textfieldDidBeginEditing, like so:
- (void) textFieldDidBeginEditing:(id)textField {
TTTableViewCell *cell = (TTTableViewCell *)[self.tableView cellForRowAtIndexPath:objc_getAssociatedObject(textField, kIndexPathId)];
[self.tableView setContentOffset:CGPointMake(cell.frame.origin.x, cell.frame.origin.y - self.tableView.sectionHeaderHeight) animated:YES];
}
This works perfectly when the user goes down the list. Expect when to user taps a cell which is partial visible on the top it doesn't reveal the entire cell just moves a bit.
Does someone know a solution to this problem?
There are UITableView methods to solve exactly this. You can use scrollToRowAtIndexPath:atScrollPosition:animated: to ask the table view to bring a cell to the top by passing UITableViewScrollPositionTop.
(You might first want to check if it's already visible to ensure it doesn't scroll unnecessarily.)

Show UITableViewCell which can then expand to show more data

I have a UITableViewCell which is currently cluttered and has too much information on the screen at once. I want to make a button, that when pushed, a small view will slide down and show the remaining information, and then when pushed again it will slide back to the original size. I was wondering how I go about doing something like this. I know NOTHING about doing this, so please be specific when pointing me in a certain direction. Thanks!
Do you want single Button for all cells in table view or you want to add button as subview on each cell
1.if you want to add button as subview on each cell
a) Add button with tag value equals to indexPath.row and set target to single method for each button.
ex
-(void)infoButonTapped:(UIButton *)sender;
Now on Click on button find the tag value of button and get the info from the array which you use to populate UITableViewCells.
b) Now create a infoview and add textview on it and set info as text prop of text view and add infoview as subview of view using UIView Animation and hide on next click
you can either use a bool variable in .h file to know hide or show infoView or you can check if infoview has superview then you have to hide infoview else add infoview as subview of self.view.
if you want a common button for all Cell
a) Now on click of button get indexPath for selected cell of tableview using tableview method
- (NSIndexPath *)indexPathForSelectedRow;
this method either return indexpath for selected cell or nil in case no cell selected
Use indexpath for get info from the array and add infoview as subview to view using step 1.b explained above.
you can also get the rect of selected row for setting the cordinate for the info view
by method of tableview
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
This may help you Show hide table
Or you can use BOOL as a property of cell and hide the subviews of UITableViewCell according to bool also resize frame of cell.
In this case, you better use the following method: -
(void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{
}
Make a call to above method in your UITableView didselectRowAtIndexPath method.
More explanation is given in below link
UITableViewCell expand and collapse

make custom UIView become first responder in custom UITableViewCell

I have three UITableViewCell subclasses. I'm displaying these in a table view in a view controller. I have, in the view controller, returning nil for tableView:willSelectRowAtIndexPath: since I want the UITextFields, in two of my UITableViewCell subclasses, to get focus and become first responder.
For the third UITableViewCell subclass, I have a custom UIView subclass that houses a UIWebView. Currently the div in the html content loaded in the UIWebView is one line tall. I previously made the div height 100% but found that scrolling started to act up. If I tap in the div the keyboard comes up. However, if the user taps any where else within this custom UITableViewCell the UIWebView div is not selected and the keyboard does not come up.
How can I get either my custom UITableViewCell or custom UIView subclass to become the first responder? Or am I going about this the wrong way?
I believe you're going about this the wrong way. Returning nil for tableView:willSelectRowAtIndexPath: won't really help your cause here.
Instead, you have a couple options. First, you could make a UIButton that sits behind your text fields in your table cell which fills the entire view, and then respond to touches on it and tell the text field to become active. Like so:
Wire up the button within your UITableViewCell subclass:
[self.button addTarget:self action:#selector(handleTouch) forControlEvents:UIControlEventTouchUpInside];
Set focus on the text field when touched:
- (void)handleTouch
{
[self.textField becomeFirstResponder];
}
The other option, and the one I like less, is to handle the selection of the cell in the delegate methods and tell the cell's textfield to become active. Like so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCellSubclass *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
In which of course you would need to add a textField property to your MyCustomCellSubclass in order to do this.
Hope this helps!

Unexpected TableViewCell highlight delay

I'm trying create TableViewCells which mimic buttons. This means that on touch down, there should be a highlight effect and on touch up should trigger the standard selected state. This works as intended, but the problem is that there is a split second delay between touch down and the highlighted state appearing. Why is this? How can I make the highlight appear immediately on touch down without the delay?
Here's the code I'm using on my TableView delegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[tableView cellForRowAtIndexPath:indexPath] setSelected:YES animated:NO];
// do something here
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:NO];
}
I suppose I don't really understand your question as you've asked it. UITableViewCell already acts "like a button" when pressed in the sense of it highlighting. From the looks of your code, it really does nothing that the tableView doesn't do natively.
Basically, the reason you are seeing a delay is because the cell already highlights on touch, and what you are doing is setting Selected to YES, then NO, but the cell already does this, so it's kind of doing the same thing twice, once on it's own, then once forced — this is the reason for the delay you are seeing.
The only thing that should go in didSelectRowAtIndexPath: is the actions you want to happen when the button is pressed, NOT what you want the cell to do or how it should behave upon being touched. There are other delegate methods that would handle these behaviors.
If you are looking to change the highlight color of the cell, then see my question/answer here.
Update
By default, the UITableView code provided by Apple does not contain the deselect method. So when you select the cell it stays selected. To deselect the cell, add the following method to didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/* The following will deselect the cell on touchUp */
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
}

Can I add a disclosure Button to only one cell in my UITableView?

I have a UITableView and I want to add a disclosure button to a cell but only when the cell is selected.
How can i do it?
Thanks
in tableView:didSelectRowAtIndexPath: save the indexPath to a member variable.
in tableview:cellForRowAtIndexPath: check, if the indexPath is the saved one and set cell.accessoryType
Do it in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//bla bla bla
}
Remember to have a variable to remove the button from the previous selected cell
In the table view cell set the accessoryType or accessoryView property. You will want to do this in the -tableView:didSelectRowAtIndexPath: delegate method.
Doing it in didSelect means that the disclosureButton only appears after the user releases the selected cell. If you want ti to appear when the cell is highlighted, you need to subclass UITableViewCell and override setSelected: or setHighlighted:
However, the whole point of a disclosureButton is that the button can be pressed and does something different then simply selecting the cell. For that there is the disclosure indicator. The whole premise of making either of these show up only when the cell is highlighted/selected doesn't seem to serve any good UI design purpose in my opinion...but maybe for what you want it does make sense.