Skip to content

Instantly share code, notes, and snippets.

- (void)viewDidAppear:(BOOL)animated{
[self subscribeToKeyboardEvents:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[self subscribeToKeyboardEvents:NO];
}
- (void)subscribeToKeyboardEvents:(BOOL)subscribe{
if(subscribe){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}else{
- (void) keyboardDidShow:(NSNotification *)nsNotification {
NSDictionary * userInfo = [nsNotification userInfo];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect newFrame = [table frame];
CGFloat kHeight = kbSize.height;
if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)){
- (void) keyboardWillHide:(NSNotification *)nsNotification {
NSDictionary * userInfo = [nsNotification userInfo];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect newFrame = [tableframe];
CGFloat kHeight = kbSize.height;
if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)){
@joaofranca
joaofranca / gist:3159576
Created July 22, 2012 12:58
gist 1: iOS - Customize UITableViewCell delete/move overlay views while editing
// editing style
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
@joaofranca
joaofranca / gist:3159582
Created July 22, 2012 13:00
gist 2: iOS - Customize UITableViewCell delete/move overlay views while editing
// cell content view indentation
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
return NO;
}
@joaofranca
joaofranca / gist:3159583
Created July 22, 2012 13:01
gist 3: iOS - Customize UITableViewCell delete/move overlay views while editing
// make cells editable
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
@joaofranca
joaofranca / gist:3159585
Created July 22, 2012 13:02
gist 4: iOS - Customize UITableViewCell delete/move overlay views while editing
// update datasource after moving
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// you should correct the data source order here to reflect the row moving
// it should be somethig like:
NSString * tmp = [sourceArray objectAtIndex:fromIndexPath.row];
[sourceArray removeObjectAtIndex:fromIndexPath.row];
[sourceArray insertObject:tmp atIndex:toIndexPath.row];
@joaofranca
joaofranca / gist:3159588
Created July 22, 2012 13:03
gist 5: iOS - Customize UITableViewCell delete/move overlay views while editing
// cells are movable
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}