I'm currently developing an iOS application. The problem is the iPad 2 I'm using for the testing runs it really slowly. The pushes and pops are slow, the lists are unresponsive, etc.
I tried to isolate one View Controller with only one UITableViewController to find out the reason for the unresponsiveness. The application was still slow.
After that, I commented the webservice call and the parsing call, leaving the application with only one UITableView, showing 30 rows of static text. Still slow.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UILabel *labelTeamA = (UILabel *)[cell viewWithTag:100];
[labelTeamA setText:#"test"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 30;
}
Other applications already installed run fine.
Please, help me finding out the problem.
Edit:
Just found that the libGoogleAdMobAds.a library was responsible for all the lag in the application. Is there any solution?
Related
I'm creating an app where it should connect to an sql database ad display its content in a table view cell. I have made the connection to the database and it works now fine, nevertheless, it does not display anything in the tableview and I cannot understand why it's not functioning well. the code is below if you may help me:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"test");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text=[NSString stringWithFormat:#"%#",[[self.entries objectAtIndex:indexPath.row] objectAtIndex:0]];
cell.detailTextLabel.text=[self.entries objectAtIndex:indexPath.row];
return cell;
}
it doesn't even display any static if I do this
cell.detailTextLabel.text=#"test";
any suggestions? thanks in advance.
I've tried so many things and I'm totally at a loss. My text isn't appearing in my cell's default text labels in TableView. The strange part is everything else does work. By that I mean, I can read and parse the data source (XML), I can create the right amount of rows (5), and I can even get the cells to contain the text data. I know this because when I use NSLog it shows this. I even double check by using didSelectRowAtIndexPath and NSLog(#"%#",cellText); and the right text is in the log! So the cell text label contains the text I want, but it's still not appearing on the screen. Instead, I just get 5 blank rows that are each selectable, and will display the right text in the NSLog when I select them but not on the screen.
I've tried the following fixes: adjusting backgroundColor and textColor (nope), trying different sample code I could find online (nope), using ViewControllers instead of TableViewControllers (nope), deleting the files and re-building them (nope), and even creating new projects with only this code to isolate the code (nope). Every time, it's still blank! I have no idea what to do.
Here's the code I'm using to grab and display the data in the tableview:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [app.listArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
theList = [app.listArray objectAtIndex:indexPath.row];
cell.textLabel.text = theList.name;
NSLog(#"%#",cell.textLabel.text);
NSLog(#"%#",theList.name);
return cell;
}
I assume that this is a new plain project that does not have anything else that could interfere. You checked with NSLog(#"%#",cell.textLabel.text) that the text is populated, you verified that the background and foreground colors are not the same. One remaining thing to check is transparency/Alpha. Make sure it is set to 1.
If this is on the simulator, try testing on a device. If you can't test on a device, try different simulator device to rule out the possibility that it is a simulator glitch.
Also, try hardcoding the label text to something like #"Abcdef" to make sure that the source of the culprit is not the data you are trying to display.
Try like this way. see how I wrote cellForRowAtIndexPath method.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
[cell.titleLabel setText:[listArray objectAtIndex:indexPath.row]];
NSLog(#"%#",cell.textLabel.text);
NSLog(#"%#",theList.name);
return cell;
}
I had this same problem but the answer to my problem was the Connection Inspector on the right hand side for the cell. The Outlet needs to be set to accessoryView for the ContentView. Just drag it over to the cell. Don't feel bad I pulled my hair out too.
Im using Xcode7 Beta and Swift
I have been looking for answers for more than 2 days now. It just does not seem to solve.
Here is the code for cell
- (myCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomData *m = (CustomData *)[self.allCustomData objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"customCell";
myCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setBackgroundColor:[UIColor colorWithRed:255.0f green:255.0f blue:255.0f alpha:1]];
[cell.customTitle setText:m.name];
[cell.customStatus setText:#"Download"];
NSLog(#"%#",cell.customTitle.text);
return cell;
}
'cell' never returns nil. the log always prints the correct text. But the cells appear empty for some reason. On load I notice the first cell appears empty, and then on scroll, randomly 2-3 cells of any order become empty. The first cell often appears back on scroll.
I can't seem to understand what the issue could be.
UPDATE
Here are two screen shots. First one is how the table loads, I have put a background color just for debugging purpose. As you see the first cell is not showing up.
The one below is the second screenshot where I changed the orientation and scrolled a bit. You see how the first cell magically appears and the second goes away.
Also for debugging purpose, I added these two methods.
- (void)tableView:(UITableView *)tableView willDisplayCell:(dtEditionCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"Display %# %d %f",cell.editionTitle.text,indexPath.row,cell.frame.origin.x);
}
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(dtEditionCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"End Display %# %d %f",cell.editionTitle.text,indexPath.row,cell.frame.origin.x);
}
The log prints as expected. All cells are visible with correct text.
I don't know if it has something to do, but the method you show is not exactly the one used by the tableview. Here is how I do it with custom cells. I'm doing it a lot and works fine:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TextCell *cell = [tableView dequeueReusableCellWithIdentifier:#"textCellId" forIndexPath:indexPath];
TextFieldContent *cellContent=[[self.dataSource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.titleLabel.text=cellContent.titleLabel;
cell.textField.placeholder=cellContent.placeHolder;
cell.textField.tag=cellContent.tag;
cell.textField.keyboardType=UIKeyboardTypeDecimalPad;
cell.textField.delegate=self;
return cell;
}
TextFieldContent is a cutom object that hold all the properties of the custom cell. For easier implementation.
I have a simple UITableView using custom UITableViewCells.
The options set on the UITableView's properties are only that the style is set to Grouped.
When I'm trying to scroll down through the different items the scroll is extremely jumpy.
I've researched this quite a bit looking at Tricks for improving iPhone UITableView scrolling performance? and a few other questions on this website. I haven't really been able to find a solution though.
EDIT ****
I use a WSDL webservice to load data into the UITableViewCells.
The cells only have a UITextView and three buttons in it.
EDIT ****
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"NavigatorCell";
NewCell *cell = (NewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"NewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.postId = [[items objectAtIndex:indexPath.row] objectForKey:#"PostID"];
cell.post.text = [[items objectAtIndex:indexPath.row] objectForKey:#"Post"];
return cell;
}
I see your NewCell is subclassed.
Don't forget to include this method into your NewCell.m
- (NSString *) reuseIdentifier
{
return #"Cell Identifier";
}
Of course #"Cell Identifier" should be the same that you use in your cellForRowAtIndexPath:.
If you fail to implement this method each cell will be generated from scratch.
Are you using a dequeReusableCellWithIdentifier? Follow the format below. Since you now mention you are loading data from the web you need to do this asynchronously to allow for smooth scrolling. To load from a webservice (asynchronously) there is a nice project just for that here
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"yourCellName";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
Setting your tableview to Reuse cells is the most basic way to ensure good performance. Basically it means that instead of creating a new cell for every cell in the tableview, your tableview will recycle the cells that are off screen. The basic setup is below, and more can be learned from the apple documentation on UITableViewDelegate linked here
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"Cell Identifier";
CustomCellClassName *cell = (CustomCellClassName *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[CustomCellClassName alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)];
//Do basic cell construction common to all cells of this type here
//Set background, image etc.
}
//Do specific cell construction here
return cell;
If you're loading data over the network for each cell, you'll see poor performance. Batch your data fetch, then when it's ready tell your tableview to reload itself.
Using Core Data as a temporary backing store, and an NSFetchedResultsController to retrieve the info from Core Data, will save you some work.
Hi Guys I am creating a iOS(Universal) application.
My problem is that in my application there is a UITableView that works fine if the application doesn't goes to background(By pressing home button or by clicking a URL link).
If the application goes into the background, when it gets active, reloading a cell or the whole table view crashes the whole application.
Any Solution???
Is removing the dequeueReusableCellWithIdentifier: will make some difference??
The code is :
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = #"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:identifier];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
Animation *animation = [animationArray objectAtIndex:indexPath.row];
cell.textLabel.text = animation.title;
if(animation.isAnimationEnabled){
cell.imageView.image = OnImage;
}else {
cell.imageView.image = OffImage;
}
return cell;
}
You have to make sure all the view controllers in your app can survive arbitrary number of cycles of view load/view unload. Check whether you remove something in viewDidUnload that is used in viewDidLoad.