Partially highlighting uitableviewcell - iOS 8 - ios

I have a custom uitableviewcell, which behaves different when run on iOS 8. It works completely fine on iOS 7. The cell get partially highlighted on selection. Here is a screenshot below for running on iOS 8:
The code that handles iOS 7 & 8 cases are as below:
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView respondsToSelector:#selector(setLayoutMargins:)]) {
return UITableViewAutomaticDimension;
} else {
return [self heightForCellAtIndexPath:indexPath];
}
}

Related

Jerky scroll with minimal UITableView

A barebones app that I created involving tableview is scrolling choppily in the simulator.
I am not able to figure why this is happening. I have worked on iOS6 and before. I am doing this in iOS 9.1
The only relevant code I have in table view is :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.listItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"reuse" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:#"%#",self.listItems[indexPath.row]];
return cell;
}
I have a hunch that it is some issue with simulator or some issue with my mac. But I can't figure out what is wrong.

Autolayout of UITableViewCell doesn't work when selecting

Autolayout of my UITableViewCell works as expected when viewing, but when I selecting a row, the UI will break, and the height of this cell will also back to default value.
For cell-related code, I just followed this tutorial "Using Auto Layout in UITableView for dynamic cell layouts & variable row heights"
Unfortunately, this tutorial doesn't cover selection part of UITableViewCell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = ...
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController pushViewController:MyViewController animated:YES];
}

UITableView not working correctly in some simulators, but works in others

I'm using a standard UITableViewController, when I run the simulator (Xcode 6, Objective-C) as iPhone 4s, 5, 5s or iPad Air it works just fine. But if I change the simulator to iPhone 6, 6+, iPad Retina it doesn't work, no data gets displayed in the table... I'm totally baffled by this. No errors anywhere.
Any ideas?
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CaseCell" forIndexPath:indexPath];
// Configure the cell
cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
return cell;
}

Resizing an UITableViewCell using AutoLayout on iOS 7 and iOS 8

I want to resize a UITableViewCell when it is selected. In iOS 7 I designed two table view cells of different heights and replaced the one with the other when selected:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
// ...
}
I set the height correspondingly:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.tableView.indexPathForSelectedRow isEqual:indexPath]) {
return 163.0f;
}
else {
return 60.0f;
}
}
Problem:
When selecting the row on iOS 8 it will load the new cell but it won't change the height of the cell. Instead it will break one of my constraints, enforcing the systems "<NSLayoutConstraint:0x7f9fdb72b1f0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f9fdb7009f0(60.6667)]>" constraint.
My first solution was to use - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath instead of - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath but this doesn't work on iOS 7.
Implementing both methods will not produced the desired result on either OS.

Swipe to delete working on multiple cells at the same time in iOS 7

I am supporting swipe to delete feature in my UITableView. I am seeing that in iOS 7, I can swipe on multiple rows and delete button appears up on all the rows. Its working fine in iOS 6. Is there a way to restrict this to one cell only the way it works in iOS 6?
- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)iIndexPath {
int aNoOfRows = self.productCount;
if (iIndexPath.row < aNoOfRows)
return YES;
return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)iTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath {
UITableViewCellEditingStyle anEditingStyle = UITableViewCellEditingStyleNone;
int aNoOfRows = self.productCount;
if (iIndexPath.row < aNoOfRows) {
anEditingStyle = UITableViewCellEditingStyleDelete;
}
return anEditingStyle;
}
This is a known bug with iOS 7. Have reported it and it should probably be fixed in next iOS release. Not sure why I got down votes here.
See this example, this way you don't need to change the tableView on editing mode and you can swipe delete on the indexPath.row > 5, also you can get the delete button being pressed in the commit int -tableView commitEditingStyle:forRowAtIndexPath::
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#pragma mark tableView delegate methods
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Test" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:#"Row %i", indexPath.row];
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// The condition for your cells to become editable
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// do whatever you need to do on the delete event for each indexPath
// this is where you remove the cell and before that you need to manipulate
// your array so when the delete is called, it gets the proper count, etc.
}
#end
Set as below to disable editing multiple cells at the same time.
tableView.allowsMultipleSelectionDuringEditing = NO;

Resources