wagashi
wagashi

Reputation: 894

ios UITableViewCell has always one extra character, why?

I use this code

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;

in

- (void)tableView:(UITableView *)tableView1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath

in order to extract the string to match a string from my array.

However, it never gets matched, as

NSLog (@"cellText length %d", [cellText length]);

always show that cellText has always one extra character, even there is no white space or extra character in my array that my table view is loaded from.

Why does this happen?

Upvotes: 0

Views: 54

Answers (2)

wagashi
wagashi

Reputation: 894

I solved it by copying the content of the files that feed table view into new files with other names, and suddenly the extra invisible character for all cells disappeared. Is this common problem? Anyway, it is solved now, yay! Thanks to yuji.

Upvotes: 0

Vidya Murthy
Vidya Murthy

Reputation: 530

The length method returns the total number of characters, but the position of each character is counted from 0, as with the arrays. Maybe this could be your problem. Could you please post some more code as to how exactly you are matching the strings.

Upvotes: 1

Related Questions