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.
Related
- (void)viewDidLoad {
[super viewDidLoad];
menuArray=[[NSMutableArray alloc]initWithObjects:#"Address",#"Restaurants",#"Deals",#"Orders",#"Account",#"Address Book",#"Settings",#"Live Chat",#"Info",nil];
tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, menuSubView.frame.size.height, self.view.frame.size.width-80, self.view.frame.size.height-menuSubView.frame.size.height)];
tableView.delegate=self;
tableView.dataSource=self;
[self.view addSubview:tableView];
}
and other methods as follows-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return menuArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reusableIdentifier=#"Cell4";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableIdentifier];
}
cell.textLabel.text=[menuArray objectAtIndex:indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70;
}
However when I run the program i am able to see the table view as desired. But when I scroll through it, table's data disappear and only blank table view remains. Can anyone help me? Thanks in advance.
--> I appreciate above answer.
--> Please try this line in "cellForRowAtIndexPath" Method...!
--> Sometimes it happens. I have solved this issue with this line in past. I hope it's useful for you.
UITableViewCell *cell = [self.tblView dequeueReusableCellWithIdentifier:#"Cell4" forIndexPath:indexPath];
I am facing issue for UITableView line separator. Line is visible for alternative rows.
Adding UIView with height 1 to the cell will give the solution but this is not the correct way. And the below code is working perfect for iOS 8 but in 9 it's showing different nature.
- (IBAction)curencySelect:(id)sender {
currencyTable = [[UITableView alloc]initWithFrame:CGRectMake(29, 257, 265,113) style: UITableViewStylePlain];
}
#pragma mark -
#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
return currencyArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyIdentifier"];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"MyIdentifier"];
}
cell.textLabel.text = [currencyArray objectAtIndex:indexPath.row];
return cell;
}
Thanks in advance.
Common problems with the simulator, which can't always display 1 pixel views. Set scale to 100% in Window->Scale.
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];
}
}
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;
}
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;