Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Alright, I'm at a wall. I'm trying to copy the SELECTED ROW from a Table View and add the contents to an ARRAY.

I tried this, but to no avail:

    [self.templist addObject:[self.songsList objectAtIndex:indexPath.row]];

Any thoughs would be appreciated. Above, I tried to add the row to an array called templist. But, no luck.

Thanks,

share|improve this question

closed as off-topic by Josh Caswell, Carl Veazey, esker, Kreiri, allprog Sep 7 '13 at 19:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance." – Josh Caswell, Carl Veazey, esker, Kreiri
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Define "no luck". Also, split up the line. Make sure the result of [self.songsList objectAtIndex:indexPath.row] gives you the expected value. Then make sure none of the ivars behind these properties are nil. – rmaddy Sep 7 '13 at 4:48
    
@user1345470 your templist array alloc or init first and after try . – Darshan Kunjadiya Sep 7 '13 at 6:40
    
Thanks for the response. I'd define "no luck" as spending a couple of hours trying different methods parsed together from various answers on multiple questions. I'll follow up on your suggestion because, honestly, I do not have any idea what value the indexPath.row returns. – Belboz Sep 7 '13 at 16:20

2 Answers 2

up vote 0 down vote accepted

What do you actually want to copy..? do you mean a tableViewCell ...

if its a tableViewCell then its an easytask..

youcan use following line:

[NSIndexPath  *index= [NSIndexPath indexPathForRow:3 inSection:0];  // Suppose cell no 3 in section 0

UITableViewCell *myCell = [tableName cellForRowAtIndexPath:index];

[yourArray addObject:myCell];

Hope this will help you.

share|improve this answer
    
Thanks for the response. I'll give it a shot. I was under the impression a ROW had many different cells with different values, so I was hoping to just copy the entire row like you would in Excel, and just paste it. – Belboz Sep 7 '13 at 16:19
NSMutableArray * templist=[[NSMutableArray alloc]init];

NSLog(@"%@",templist);

[templist addObject:[self.songlist objectAtIndex:indexPath.row]];

NSLog(@"%@",templist);

Try to use NsMutable array...

share|improve this answer
    
downvoter why downvoting me... – Jitendra Sep 7 '13 at 5:27
    
I'm not the down voter but I think your last log should print templist, too. – HAS Sep 7 '13 at 5:37
1  
@HAS sory it was my silly mistake check my update now... – Jitendra Sep 7 '13 at 5:43
    
Yeah, my guess is that s/he didn't alloc omit the array (which is a property btw ;) not a local variable) but that's the last thing I'd recommend ;) you can lazily instantiate it there where you now create it and I'll +1 ya ;) – HAS Sep 7 '13 at 5:48
    
i am just telling him follow that way. – Jitendra Sep 7 '13 at 5:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.