hi
I am editing table view in iphone. I m doing this with the following code written under viewDidLoad() method.
UIBarButtonItem* barBtnItemEdit = self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self
action:#selector(turnOnEditing)];
My table view goes in edit mode correctly, but it slides a little to the right. Now what i want to do is to lock the table so that it remains on its position even in edit mode. I am writing customized code for table in editing mode instead of default Delete or insert behavior..
I've implemented the following code to stop displaying "red-color delete" button in front of each row...,
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
but UITableVIew still slides a little to the right. Now how to lock the table so that it doesn't change its position in edit mode
Best regards,
Abdul Qavi
I think you also need to add:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Related
I made a project in interface builder with the Master-Detail Template and I'd like to get rid of the edit button.
I wrote (in MasterViewController):
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
This disables the edit button, however the button is still there.
Then I tried (in the viewDidLoad, after connecting the tableView property to my MasterViewController class):
[self.tableView setEditing:NO];
However, the button is still there.
You need to remove the button altogether. setEditing has to do with wether or not the tableview is in edit mode or not, so try:
self.navigationItem.rightBarButtonItem = nil;
In your viewDidLoad method.
Also make sure you don't see a line of code in viewDidLoad that looks like:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
If yes, delete or comment it out.
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;
}
With reference to this question: Exit Edit Mode
about exiting edit mode when the last row is being deleted, my question is - how do you update the navigation bar "edit" item? After deleting the last row, I'd like to remove this nav bar item altogether AND exit edit mode (which is done per the question below) AND revert this button status back to "Edit" (rather than "Done" which is its status after deleting the last row).
Thats what I am doing now:
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
...
if ([section count] == 0) { //last row in the section
[listOfItems removeObject:accessNumbers]; //updating my data source
tblSimpleTable.editing = NO; //added per the question above
// self.navigationItem.rightBarButtonItem = nil; --> thats what ideally i would want to do
// [self setEditing:YES animated:YES]; --> adding this manually doen't help
}
else
{
...
}
}
}
Thank you for the help!
UPDATE: adding this line doesn't help. I stil need to click on the nav bar item "Done" to exit the editing mode.
[self.tblSimpleTable setEditing:YES animated:YES];
if I also hide the nav bar item, I essentially can't exit the edit mode at all, and the screen is frozen (I have some other buttons on the view that simply dont react to touch anymore in that case).
According to the apple documentation, you cannot call [self.tableview setEditing:NO animated:YES] from within your tableView:commitEditingStyle:forRowAtIndexPath:. Here is the relevant excerpt:
Note: The data source should not call setEditing:animated: from within its implementation of tableView:commitEditingStyle:forRowAtIndexPath:. If for some reason it must, it should invoke it after a delay by using the performSelector:withObject:afterDelay: method.
Presumably one could then create a selector that turns off editing mode and removes the button.
Can you enforce this rule in another callback?
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
BOOL answer = [section count] > 1;
self.navigationItem.rightBarButtonItem = (answer)? self.editButtonItem : nil;
return answer;
}
I was having issues doing the same thing (not able to get the status of the barButtonItem to revert to 'Edit' after calling setEditing) and learned from this answer https://stackoverflow.com/a/11490594/2888978 that the way to get change the 'Edit' back to 'Done' on the nave bar is to call setEditing on the view controller, not the table. Then you can set the barButtonItem to .None to remove it from the nav bar when the table is empty.
So instead of calling:
self.tableView.setEditing(false, animated: true)
You would call:
self.setEditing(false, animated: true)
Otherwise only the editing mode of the cells will change.
To leave editing mode, use this:
[self.tableview setEditing:NO animated:YES];
To remove the button all-together, use:
// Note that this only removes the right-most button. If you want to remove all of the buttons on the right side, use rightBarButtonItems instead.
self.navigationItem.rightBarButtonItem = nil;
// If you want it animated, use:
[self.navigationItem setRightBarButtonItem:nil animated:YES];
I am working on UITableView and I am doing a deletion. As far as I know there are 2 ways to delete a row
swiping from the left to right and Delete button will appears so that you can do a deletion
add EDIT button to right top right or left. By clicking on it, EDIT will change to DONE and each row of a table will have a red circle
with (-) sign in front of each. Click on it , delete button will
appear and you can process
I noticed that if you do have an EDIT button and use the method 1 to delete, the EDIT button also change to DONE...However, after swiping it, mine is still EDIT. does any one encounter this problem before, please help. All comments are welcomed here. Thanks
Swipe to delete happens when the view is not in edit mode. It's supposed to be a quick way to delete items when browsing the view. Check out how it works in the Mail app for example - you can either tap to edit all rows, or just swipe to delete one of them.
So basically it's working correctly.
However, if you want to override the standard behaviour, you can call setEditing: on the viewController to toggle the mode programmatically, which will also update the edit button.
Add the Edit button using the ViewdidLoad method
-(void)viewDidLoad;
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [self editButtonItem];
}
And for the delete method
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
[array removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPath:[NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationFade];
[self.tableView reloadData];
}
To get this behavior you need to implement these two delegate methods:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.editing = YES;
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.editing = NO;
}
Is there a possibility to reset a UISearchbar with searchDisplayController programmatically which is active and already contains text?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.searchDisplayController.searchResultsTableView) {
searchDisplayController.searchResultsTableView.hidden = YES;
searchBar.showsCancelButton = NO;
[searchBar resignFirstResponder];
}
}
This solution is working, but there is still text in the searchBar. If i add those lines of code:
searchBar.text = #"";
There is always a black transparent view left.
Any solutions?
Here ya go. This is a delegate method called when the user hits cancel. If you want to wire it up differently just declare your search bar as an outlet and reference it. Anyway:
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = #"";
[searchBar resignFirstResponder];
}
Pretty sure what you're looking for is UISearchDisplayController.active
From the SDK:
#property(nonatomic, getter=isActive) BOOL active
If you set this value directly, any change is performed without animation. Use setActive:animated: if a change in state should be animated.
When the user focus in the search field of a managed search bar, the search display controller automatically displays the search interface. You can use this property to force the search interface to appear.
This thread is so old it has dust. Still here we are in swift so
<#your UISearchController variable#>.isActive = false
don't you have to retire the firstResponder
[self.searchBar resignFirstResponder]
You can also explicitly hide the resultsTableView, if that's what you want:
searchDC.searchResultsTableView.hidden=YES;
(searchDC is an instance of UISearchDisplayController)
This will help you with hiding the Cancel button and stuff: http://www.alexandre-gomes.com/?p=418