IOS 6 UITableViewCellEditingStyle Overlapping TableViewCell Labels - ios6

I am working with IOS 6 UITableView and my problem is that whenever i put the table view into edit mode, the edit control that appears next to the table view cell of deletestyle ( UITableViewCellEditingStyleDelete ) overlaps two labels ( xyzname and xyzcollege ).
I did not have this problem in IOS 5 (with same code).
CODE:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:#"friends"ofType:#"plist"];
NSDictionary *xyz = [[NSDictionary alloc]initWithContentsOfFile:path];
_names = [xyz objectForKey:#"name"];
_colls = [xyz objectForKey:#"college"];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
NSInteger count =_names.count;
if(self.editing)
{
count++;
}
return count;
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
saumyaTableViewCell *cell;
cell = [_saumyaTable dequeueReusableCellWithIdentifier:#"saumyacell"];
if(indexPath.row < _names.count)
{
cell.xyzname.text = [_names objectAtIndex:indexPath.row];
cell.xyzcollege.text = [_colls objectAtIndex:indexPath.row];
}
else
{
cell.xyzname.text = #"Add name.";
cell.xyzcollege.text = #"Add College";
cell.editingAccessoryType =
UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
-(void)setEditing:(BOOL)editing animated:(BOOL) animated
{
if( editing != self.editing )
{
[super setEditing:editing animated:animated];
[_saumyaTable setEditing:editing animated:animated];
NSArray *indexes = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:_names.count inSection:0]];
if (editing == YES )
{
[_saumyaTable insertRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationLeft];
}
else
{
[_saumyaTable deleteRowsAtIndexPaths:indexes
withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < _names.count)
{
return UITableViewCellEditingStyleDelete;
}
else
{
return UITableViewCellEditingStyleInsert;
}
}
IMAGE DESCRIPTION:
1.UITableViewCell has two labels(xyzname and xyzcollege)
2.UITableViewCellEditingStyleDelete overlaps these two labels when cell goes into edit mode
What is to be done if i want those labels to automatically animate on the right side when my view goes into the edit mode and again animate to their original positions after coming out of the edit mode?
THANK YOU

Related

UITextView - How to remain cursor after hide keyboard

I'm trying to make a UITextView that user could input text and emoticons.
And I got a problem with the cursor displaying.
My goal is to make the cursor appears as normal while selecting emoticon(Keyboard is hidden).
I know it could be done because a app called "Kakao Story" have the feature.
Does anybody have a solution about it?? Thanks.
I found a way to make keyboardView hidden to access my purpose.
Here is the code
+ (void)hideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:YES];
}
}
}
}
+ (void)unhideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:NO];
}
}
}
}
+ (UIView *)getPeripheralHostViewFromView:(UIView *)superView
{
if ([superView.description hasPrefix:#"<UIPeripheralHostView"]) {
return superView;
}else if([superView.description hasPrefix:#"<UIKBInputBackdropView"]) {
return superView.superview;
}else {
for (UIView *subView in superView.subviews) {
UIView *keyboardHostView = [self getPeripheralHostViewFromView:subView];
if (keyboardHostView) {
return keyboardHostView;
}
}
}
return nil;
}

heightForRowAtIndexPath =0 but it still display the label in its row

I have a table view and I set all of the odd cell height = 0, In odd cell I had some labels. When it show up the table view, the label in odd cell appear in the even cell. Is there any way to make the label vanish? This problem happened in ios 6
p/s:
in ios 7: it work right.
i already had the method : [tableView beginUpdates]; [tableView endUpdates];
Thanks.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// show odd row
if (selectedRow == indexPath.row) return 78;
// hide odd row and show even row
if (indexPath.row %2 ==0){
return 88;}
else{
return 0;}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row%2 == 0){
//user click on even row -> display the next row
selectedRow = indexPath.row+1;
[tableView beginUpdates];
[tableView endUpdates];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int index = indexPath.row / 2;
if (indexPath.row %2 ==0){
static NSString *CellIdentifier = #"PhraseViewCell";
PhraseCellVietnamese *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *phrase = [[phrases objectAtIndex:index] objectForKey:#"vietnamese"];
NSNumber *checkFavorite = [[phrases objectAtIndex:index] objectForKey:#"favorite"];
NSNumber *phraseId =[[phrases objectAtIndex:index] objectForKey:#"_id"];
[cell SetInfo:phrase :checkFavorite.intValue :phraseId.intValue];
return cell;
}
else{
static NSString *CellIdentifier = #"PinyinViewCell";
PinYinViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *pinyin = [[phrases objectAtIndex:index] objectForKey:#"pinyin"];
NSString *chinese = [[phrases objectAtIndex:index] objectForKey:#"chinese"];
NSString *voice = [[phrases objectAtIndex:index] objectForKey:#"voice"];
[cell setInfo:pinyin :chinese :voice];
return cell;
}
}
[cell setClipsToBounds:YES]; in cellForRowAtIndexPath
worked for me. Hope you found your solution.
After reading user2799736 answer I changed
Clip Subviews
to YES in .xib file.
Worked for me.

by Adding Polyline(path) on MKMapview crashing the app in ios6

I have a requirement to adding a path in my MKMapview between two annotation pin. There is no issue with ios 5 or older but when i try to run app in ios 6 app is surprisingly quit. below is my code. If there is any correction in my code then please suggest me.
1.So my question is suggest the best way how to decrees memory in my following code so that i can solve crash in my Application.
- (void)viewDidLoad
{
NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoints:pathArray mapView:_mapView];
[_mapView addAnnotation:annotation];
[annotation release];
[pathArray removeAllObjects];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(#"%s",__FUNCTION__);
if ([annotation isKindOfClass:[NVPolylineAnnotation class]])
{
NSLog(#"=========ANOTATION=========NVPolylineAnnotationView START");
//ann=[ann initWithAnnotation:annotation mapView:_mapView];
NVPolylineAnnotationView *ann=[[NVPolylineAnnotationView alloc] init];
return [[ann initWithAnnotation:annotation mapView:_mapView] autorelease];//[[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation mapView:_mapView] autorelease];
}
else if([annotation isKindOfClass:[MapViewAnnotation class]])
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pointers"] ;
// annView.rightCalloutAccessoryView = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
annView.animatesDrop=NO;
annView.canShowCallout = TRUE;
return [annView autorelease];
}
else if([annotation isKindOfClass:[PlacePin class]])
{
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
}
else {
[mapView.userLocation setTitle:#"I am here"];
}
return pinView;
}
}
return nil;
}
- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(#"%s",__FUNCTION__);
// fixes that some marker are behind the polyline
for (int i=0; i<[views count]; i++)
{
MKAnnotationView *view = [views objectAtIndex:i];
if ([view isKindOfClass:[NVPolylineAnnotationView class]])
{
[[view superview] sendSubviewToBack:view];
/* In iOS version above 4.0 we need to update the polyline view after it
has been added to the mapview and it ready to be displayed. */
NSString *reqSysVer = #"4.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[self updatePolylineAnnotationView];
}
}
}
NSLog(#"----------didAddAnnotationViews");
}
- (void)updatePolylineAnnotationView
{
NSLog(#"%s",__FUNCTION__);
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
[mapView selectAnnotation:mp animated:NO];
*/
for (NSObject *a in [_mapView annotations])
{
if ([a isKindOfClass:[NVPolylineAnnotation class]])
{
NVPolylineAnnotation *polyline = (NVPolylineAnnotation *)a;
NSObject *pv = (NSObject *)[_mapView viewForAnnotation:polyline];
if ([pv isKindOfClass:[NVPolylineAnnotationView class]])
{
NVPolylineAnnotationView *polylineView =
(NVPolylineAnnotationView *)[_mapView viewForAnnotation:polyline];
[polylineView regionChanged];
}
}
}
}

Search bar and search display controller with segue

Never called when a search table cell is tapped
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Show Detail"])
{
Player *player = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
[segue.destinationViewController setPlayer:player];
}
}
This filters the list correctly, but the prepareForSegue is never called when a search table cell is tapped.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Player Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.tableView)
{
// normal table view population
Player *player = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[NSString alloc] initWithFormat:#"#%# %# %#", player.number, player.firstName, player.lastName];
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:#"%#", player.position];
[cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:#"playerplaceholder.jpg"]];
}
else if(tableView == self.searchDisplayController.searchResultsTableView)
{
// search view population
Player *player = [self.filteredFetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[NSString alloc] initWithFormat:#"#%# %# %#", player.number, player.firstName, player.lastName];
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:#"%#", player.position];
[cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:#"playerplaceholder.jpg"]];
}
return cell;
}
you need to put IF that check if the search have results.
like in this code:
if ([[segue identifier]isEqualToString:#"ShowDetails"])
{
ShowDetailsViewController *sdvc = (ShowDetailsViewController *)[segue destinationViewController];
NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
Books *selectedBooks = nil;
if(self.searchDisplayController.active)
selectedBooks = (Books *)[[self searchResults]objectAtIndex:[[[[self searchDisplayController]searchResultsTableView]indexPathForSelectedRow]row]];
else
selectedBooks = (Books *)[[self fetchResultsController] objectAtIndexPath:indexPath];
sdvc.currentBooks = selectedBooks;
}

uikeyboard leaves a black portion on top on navigation

I have a form on the ipad which has many textfield and a button at the end. There are some fields which come under the keyboard when it is active. In order to pull the hidden texfield behind the keyboard to be visible I am using the following code.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
_scrollView.frame=CGRectMake(0, 0, 1024, 655);
[self animateTextField:textField up:NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
CGPoint temp = [textField.superview convertPoint:textField.frame.origin toView:nil];
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait)
{
// NSLog(#"portrait");
if(up)
{
int moveUpValue = temp.y+textField.frame.size.height;
animatedDis = 264-(1024-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
if(up)
{
int moveUpValue = 1004-temp.y+textField.frame.size.height;
animatedDis = 264-(1004-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
if(up)
{
int moveUpValue = temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
}
}
else
{
if(up)
{
int moveUpValue = 768-temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
_scrollView.frame = CGRectMake(0, 0, 1024, 655-240);
}
}
if(animatedDis>0)
{
const int movementDistance = animatedDis;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
if (orientation == UIInterfaceOrientationPortrait)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationLandscapeLeft)
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
else
{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}
[UIView commitAnimations];
}
}
I am also using the scroll view. My issue is that when the keyboard is active and i press my button it take me to the next screen. Now if i navigate back, the keyboard is active and the prior animations are set. Now if i hide the keyboard, the entire view scrolls down leaving a black portion on top. How to handle this situation?
Okay. After much research I found a simple method. It is the use of notifications.
In my viewDidLoad i added these two keyboard notifications.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
These are the 2 selector methods:
-(void)keyboardWasShown:(NSNotification *)aNotification
{
if (displayKeyboard==YES) {
return;
}
NSDictionary* info = [aNotification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
//NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
NSLog(#"kbw====%fkbh====%f",keyboardSize.width,keyboardSize.height);
offset = _scrollView.contentOffset;
CGRect viewFrame = _scrollView.frame;
NSLog(#"svw====%fsvh===%f",viewFrame.size.width,viewFrame.size.height);
viewFrame.size.height -= keyboardSize.height-49;
NSLog(#"new view hgt =====%f",viewFrame.size.height);
_scrollView.frame = viewFrame;
CGRect textFieldRect = [activeField frame];
textFieldRect.origin.y += 10;
[_scrollView scrollRectToVisible: textFieldRect animated:YES];
displayKeyboard = YES;
}
-(void)keyboardWillBeHidden:(NSNotification *)aNotification
{
if (!displayKeyboard) {
return;
}
_scrollView.frame = CGRectMake(0, 0, 1024, 655);
_scrollView.contentOffset =offset;
displayKeyboard = NO;
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
activeField = textField;
return YES;
}
displayKeyboard, offset and activeField are declared in .h file.
Also remember to remove the notifications in viewDidDisappear:animated
Although this method is quite different than the previous one stated, this one does not leave a black portion on the top while navigating between classes when the uikeyboard is active.
Also what i noticed was if i used the deprecated UIKeyboardBoundsUserInfoKey i used to get the correct width and height of the keyboard(i am working only in landscape mode). Whereas when i used UIKeyboardFrameBeginUserInfoKey the width and height values were interchanged. I am still trying to figure out this problem.
Also when the keyboard used to appear, a fixed space of 49px was appended to above it. I assumed that that was my tabbar height and therefore subtracted 49.

Resources