I have implemented a section index, letters at the right of the table view that allow quickly jumping to a section, in my app. I would like to disable user interaction with that section index in some situations, but there is no property on UITableView that allows directly accessing the section index.
How can I disable user interaction for section indexes?
I have disabled interaction with the table itself so that you cannot scroll or tap any cell, but this still allows interacting with the section indexes, so it will scroll to each section upon tapping a section icon.
self.tableView.userInteractionEnabled = NO;
If it's not possible to disable interaction with the section index itself, is there a way to prevent changing the scroll position of the table? That's exactly what I wanted to obtain.
As an alternative, if you wish to allow scrolling - so users can see what's there - but prevent them from making selections, etc. you can do the following instead:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.tableViewIsDidabled)
return nil;
else
return indexPath;
}
and, setting the sectionForSectionIndexTitle to nil.
I found a solution.
Keep a BOOL to know when the section indexes should be disabled.
Then in tableView:sectionForSectionIndexTitle:atIndex: just return -1 to prevent scrolling when tapping indexes.
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (self.tableViewIsDisabled) {
return -1;
}
...
}
UITableView *tab;
mm to disable scroll..
tab.scrollEnabled = NO;
if you wanna use it in certain situations..
you can try with a powerful..
if(...)
tab.scrollEnabled = NO;
Related
My table view is in editing mode allowing my cells to be moved around. Is it possible to also add swipe to delete, NOT using the red-circle-delete button.
I want to be able to show just the move cell image, allowing moving, and also have a swipe to delete.
Is this possible?
This is what I currently have going on.
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1) {
return UITableViewCellEditingStyleDelete;
}
else
return UITableViewCellEditingStyleNone;
}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1)
return YES;
else
return NO;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
It is definitely possible, though not as simple as you'd probably like. There are three parts to this:
The "swipe" gesture
The UI animation
The delete action
The "swipe" gesture should probably not be a UISwipeGestureRecognizer. UIPanGestureRecognizer will update as the user moves their finger around and matches what the user expects.
The animation should have two parts: update and complete. Update should simply pan the cell view inside of the cell to follow along with the user's finger. Once the gesture has reached a point of "completion" then animate the cell view going off screen.
Lastly, the delete action should be familiar if you've used the UITableViewDelegate methods. If not, here's a link to a helpful answer on the subject.
I would actually implement these out of order. First, programmatically test deleting a row. When that works, add an UIPanGestureRecognizer to call the delete row. Then move the cell view around with the pan gesture. Finally, animate the completion of the cell view moving around.
I want to implement the Tab View like Apple has in their Apple Maps when you select a location and tap on the more details to reviews additional information about that location.
What would be the best way to implement this or how do you think Apple has implemented it. I know each tab view has a Table View inside each. Also for the Photos tab how do you think they implemented the content inside that tab. Was it using UICollectionView or a table view with a custom cell that has 4 photos in each cell row?
It looks like they're using one UITableView and on UISegmentedControl. With this combination every time the user selects and index on the segmented control, it changes a condition in the table's datasource and reloads the data. Here's an example of what something like that could look like to conditionally change the number of rows in the table
- (IBAction)segmentValueDidChange:(UISegmentedControl *)sender
{
NSLog(#"%d",sender.selectedSegmentIndex);
[self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.segment.selectedSegmentIndex == 0) {
return 5;
}
return 10;
}
I have a tableView with 4 sections. I want to enable editing (move/drag/ rearrange ) the cells only within the forth section. When I set: tableView.editing = YES I get all the table view to be in editing mode. This How to limit UITableView row reordering to a section helped me as I can now rearrange cells from a section only within their "root" section.
What I mean is if the cell is in the 1st section then I only get to rearrange within the 1st section and not the others. My goal is to enable editing only with The 4th section therefore putting in Move/drag Mode only the cells within the 4th Section. Does anyone know how I can do this?
You can achieve this by implementing this delegate method
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 3) {
return YES;
} else {
return NO;
}
}
I have a UITableView where I want to be able to insert rows via the Insertion Control (green plus icon). (I originally had this working with the Add control on the navigation bar, but with 'back', 'add', and 'edit' controls I felt the navigation bar was a bit cluttered).
I got this working, but I don't like the way this interacts with the reorder control. My table only has one section; the insertion row will always be shown as the last row in the table, and it should not be reorderable.
I implemented canMoveRowAtIndexPath: to return false for the insertion control row, but this is only a partial solution. That removed the ability to drag the insertion row. However, nothing prevents a user from selecting a movable row and dragging it beneath the insertion controller row. (And if allowed, this crashes the app).
The workaround I've implemented is to check the to location in moveRowAtIndexPath:toIndexPath. If the destination location is below the insertion row, I do not perform the move, and I call [tableView reloadData] to redraw the previous table state. This works, but the appearance is clunky -- the row just snaps back to its previous position with no indication why.
Is this the correct behavior here -- or is there a more elegant solution? Ideally, I'd like the user to not be able to drag the row to an illegal location in the first place, but I'm not sure there is any mechanism to prevent it.
You need to implement the tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: delegate method. The implementation should return an appropriate index path based on whether the row can be targeted to the desired row or not.
Here's the implementation:
// Don't allow dragging any moveable row below the insertion control
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath: (NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
int proposedRow = proposedDestinationIndexPath.row;
int maxRow = [[[SADeckStore sharedStore] allDecks] count] - 1;
if (proposedRow < maxRow)
return proposedDestinationIndexPath;
else
return [NSIndexPath indexPathForRow:maxRow inSection:[proposedDestinationIndexPath section]];
}
I know it's the default property of rearrangement of tableviewcells when UITableView is in editing mode & user just reorder the Rows which is handled by UITableViewController.
As per Apple Doc : Reordering of Rows
Now what I want to do is, when I drag the cell over other cells, the backend cells should not get rearranged automatically, just the cell on which I drop the dragged cell should gets rearranged, a kind of Swapping between two cells.
For better understanding, please refer the below image. I should be able to Shift Jones to Room1 & the tableview controller should able to automatically be shifting Smith2 to Room3.
Below are delegates methods which I am using :
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
NSString *temp = [roomstoringArray objectAtIndex:sourceIndexPath.row];
[roomstoringArray removeObjectAtIndex:sourceIndexPath.row];
[roomstoringArray insertObject:temp atIndex:destinationIndexPath.row];
// [temp release];
}
Problem is :
How can I stop other cells to get rearranged automatically while I
am dragging the cells over other.
There none of the delegate method which gets called when one used to
Drag the cell over others, only method called is
moveRowAtIndexPath when one drop the cell on it. So, even can't check for some condition & didn't find any scope of this enhancement
within existing TableView.
Is there any property with the TableView where I can stop such kind of behavior to perform the swapping between two cells only where rest of rows remain at the same indexPath.Alos, can someone please help me out with some-other way,if any.
For Problem you mention, Please check UITableView Delegates from here.
Below methods are helpful to you.
targetIndexPathForMoveFromRowAtIndexPath
canMoveRowAtIndexPath
For Swap b/w two rows you can get idea by this answer.