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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:01:20+00:00 2026-06-06T22:01:20+00:00

How do I read always the most upper line (cell.textLabel.text) in a UITableView? I

  • 0

How do I read always the most upper line (cell.textLabel.text) in a UITableView?

I have two slightly different approaches;

1:

UITableViewCell *cell2 = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText2 = cell2.textLabel.text;
NSLog (@" cellText2 = %@", cellText2);

2:

NSMutableString *newidea = [self.array objectAtIndex:indexPath.row];

NSLog (@"newidea = %@", newidea);

Both codes are inside the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

self.array is same array that fills up the tableView.

The former approach always shows text from the sixth cell. The latter approach always shows text from the fifth cell. In my tableview there is four cells at a time.@

What I want to get is the text from the most upper cell.

  • 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-06T22:01:22+00:00Added an answer on June 6, 2026 at 10:01 pm

    I think you have the wrong approach. You don’t read values from cells, instead you let the cells read values from your data array. A cell can always have an arbitrary value since they are reused. Even if you have 30 “cells” in your table view there may only be 5 existing actual cells. When a cell goes outside the table view when you scroll, it is moved to the bottom and reused as the next cell. That’s why you always have to set the values for each cell on the index path.

    Instead you should get the value in the first cell from your data array if you have one. When the table view asks what title the cell att indexPath.row == 0 should have, you give it to it in cellForRowAtIndexPath, for example from an array called “_cellTitles” containing 30 strings for 30 different cells.

    If you want to get the text from the “most upper” visible cell, then you can call indexPathsForVisibleRows on the table view. The first object in the returned array is the index path for the most upper visible cell. You can check the string in your array at index indexPath.row.

    Example:

    NSArray *visibleRows = [self.tableView indexPathsForVisibleRows];
    NSIndexPath *firstVisibleCell = [visibleRows objectAtIndex:0];
    NSString *firstVisibleCellTitle = [_myDataArray 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 a navigation controller with a table view. In most tutorials I've read
Does Java have a default System Environment Variable that will always be read/appended when
I know there are several estimating questions here, and I have read through most
I'm always using onclick() event in most of my projects. But, I read about
I'd like to know what's the best way (read most elegant) to have a
I am new to php, I need to read a text file's 5th line
I always read that one reason to chose a RESTful architecture is (among others)
You always read that for-in loops should check o.hasOwnProperty(k) to skip over Object.prototype. Well,
You always read in changelogs when your system or browser or any program updates
I always read that I should use model = Model(a=5, b=6) model.save() But I

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.