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 8227529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:09:16+00:00 2026-06-07T16:09:16+00:00

My problem is the following: I assign a mutable array to the cellForRowAtIndexPath so

  • 0

My problem is the following: I assign a mutable array to the cellForRowAtIndexPath so that it displays each array object in a cell. So far so good, the cells are displayed as expected. Now i want a display (according to a condition) a UILabel in the first cell, so that the other mutable array objects will be shifted to the second cell, and third, etc.
The issue is that, when i test that condition, and it’s true, the UILabel is displayed in the first cell with the first object. So actually, two elements are in the same cell, which is not what i expect. I want (when the condition is true) to shift all the elements, so that they will be displayed from the second cell in order to leave the first cell to the UIlabel.

My relevant code which doesn’t give me what i expect, is this:

- (UITableViewCell*)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


     UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"any-cell"];


 // Add and display the Cell     
      cell.tag = [indexPath row];
      NSLog(@"cell.tag= %i",cell.tag);
      //test the condition, if it's ok, then add the label to the first cell
      if ([self isNoScoreLabelDisplayed] && cell.tag==0) {
        UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 220, 50)];
        [lbl setBackgroundColor:[UIColor greenColor]];
        [cell addSubview:lbl];
      }
    cell.tag = [self isNoScoreLabelDisplayed]?[indexPath row]+1:[indexPath row];//here i wanted to shift the tags in case the condition is true, so that all the elements will be displayed from the second cell. But seems not doing what i want :(


      //
      if (indexPath.row < cellList.count) {

            [cell addSubview:[cellList objectAtIndex:[indexPath row]]];//cellList is the mutable array from which i get all the elements to display in the cells

      }else{

            [cell addSubview:nextButton];
      }


      return cell;
}

Am i missing something in my logic? thanx in advance.

  • 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-07T16:09:18+00:00Added an answer on June 7, 2026 at 4:09 pm

    You can insert your label’s text as a first element in your container and check for it. This way you will save yourself any need for index offsets and further complications of your code.

    E.g.

    [cellList insertObject:@"Label name" atIndex:0];
    if ([cell tag] == 0) {
        // add required label
    }
    else {
        // do whatever you do for your standard cells, getting them with [cellList objectAtIndex:[indexPath row]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. I assign to any object in my database a
I have the following code, The problem is when I'm trying to assign the
Struggling with the following problem. I have an attribute that defines the name of
I have the following problem that I need to express. There are persons, workplaces
My problem is the following: I need to assign a value to the recordset.
one can assign a probability to each element of an array by simply deviding
I have a problem following from my previous problem . I also have the
Following problem: I want to render a news stream of short messages based on
The following problem happens on both Safari and Chrome, so probably a WebKit issue.
I have following problem: I have to make a ASP.NET Webapplication with a two-row

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.