Sjors
Sjors

Reputation: 29

Use DidSelectRowAtIndexPath to change a NSMutableArray

I thought I figured out myself how to do this question, but it won't work. The code I used:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
     //timedText = a NSString

    [timed replaceObjectAtIndex:1 withObject:timedText];
    [SpelerTable reloadData];
}

Can someone tell me what I am doing wrong? Also, I'd like to not use "replaceObjectAtIndex:1" but use the selected cell.

Thanks in advance.

Upvotes: 2

Views: 241

Answers (4)

Vishal
Vishal

Reputation: 556

Try This code

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
     //timedText = a NSString

    [timed replaceObjectAtIndex:indexpath.row withObject:timedText];
    [SpelerTable reloadData];
}

if everything right in your other code thn it will work.

Upvotes: 0

Resh32
Resh32

Reputation: 6590

To use the cell:

UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPath];

Upvotes: 0

Mario
Mario

Reputation: 4520

    [timed replaceObjectAtIndex: indexPath.row withObject:timedText];

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122401

Why index 1 and not indexPath.row? Plus you don't need to reload the whole table; just the row that changed:

[timed replaceObjectAtIndex:indexPath.row withObject:timedText];
[spelerTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                   withRowAnimation:UITableViewAnimationAutomatic];

Upvotes: 1

Related Questions