Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:11:54+00:00 2026-06-05T00:11:54+00:00

I have a function that looks something like this: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

  • 0

I have a function that looks something like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// instantiate the cell

if(indexPath.row >=4 && indexPath.row <=5)
{
[CustomTableCell addGradient];
}
}

So basically, only rows 4 and 5 should have a gradient background. When the tableview first loads up, rows only rows 0 to 4 are visible and don’t have gradient background which is perfect. When I scroll a little down to see rows 4 and 5, the gradient appears on them, which is great again. but when I scroll back up to the first row, all of a sudden i see a gradient on the first row!!! But i never asked row 0 to have a gradient! Additionally, when i scroll down a bit, i see gradients applied to some rows and not others. Why is this happening?

here’s the addGradient function incase it’s useful:

- (void) addGradient
{
    if([self.layer.sublayers count] >0)
    {
        if([[self.layer.sublayers objectAtIndex:0] isKindOfClass:[CAGradientLayer class]])
            return;
    }

    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = self.bounds;

    gradient.colors = [NSArray arrayWithObjects:(id)[UIColor blueColor].CGColor, (id)[UIColor redColor].CGColor, nil];

    [self.layer insertSublayer:gradient atIndex:0];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:11:55+00:00Added an answer on June 5, 2026 at 12:11 am

    I just realized that iPhone/cocoa is actually re-using an existing cell in memory for cellForRowAtIndexpath to draw cells that appear on screen. So that’s why the cell still has a gradient layer I had set before. So i updated my stylecell function to remove a layer if it exists, by using this code:

    - (void) styleCell
    {
        if([self.layer.sublayers count] >0)
        {
            if([[self.layer.sublayers objectAtIndex:0] isKindOfClass:[CAGradientLayer class]])
            {
                [[self.layer.sublayers objectAtIndex:0] removeFromSuperlayer];
    //            return;
            }
        }
    
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = self.bounds;
    
        gradient.colors = [NSArray arrayWithObjects:(id)[UIColor blueColor].CGColor, (id)[UIColor redColor].CGColor, nil];
    
    
        [self.layer insertSublayer:gradient atIndex:0];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a constexpr function that looks something like this: constexpr int foo(int bar)
I have a script that looks like this #!/bin/bash function something() { echo hello
I have a thread function that looks something like this: DWORD WINAPI Thread_ProcessFile( LPVOID
I have a function that looks something like this: //iteration over scales foreach ($surveyScales
So, I have a function that looks something like this: function getUnits(squad_id) { $.ajax({
I have a function in a module that looks something like this: module MyLibrary
I have code, that looks something like this: (function($) { $(document).ready(function() { function getHash(){
So I have a function that looks something like this: float function(){ float x
I have a function that looks something like this: function fun() { $pMana <
So I have a code that looks something like this $(.something).live({ mouseover:function(e){ //do stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.