Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-07-2011, 01:22 AM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Question Reordering a cell error

Hi All,

I have a problem with an array.

My array contains data for UITableView cells, the problem I have implemented the reordering ability and used the following code;

Code:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
      toIndexPath:(NSIndexPath *)toIndexPath {
    
    NSString *item = [[arryData objectAtIndex:fromIndexPath.row] retain];
    [arryData removeObjectAtIndex:fromIndexPath.row];
    [arryData insertObject:item atIndex:toIndexPath.row];
    [item release];
}
In Xcode I have a warning;

'NSArray' may not respond to 'insertObject:atIndex'

against;

Code:
   [arryData removeObjectAtIndex:fromIndexPath.row];
   [arryData insertObject:item atIndex:toIndexPath.row];
When I run the debugger I keep hitting the following error;

Code:
Thread 1: Program recieved signal: "SIGABRT"
(Am I the only one who finds the Output feedback pointless? Coming from VS, the error output is very generic)

Can you help?

Cheers

Carl
scrumsolutions is offline   Reply With Quote
Old 06-07-2011, 05:44 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

NSArray is immutable. Hence the warnings, and also the crash.

You want NSMutableArray for what you are doing.

Tip: if you see a warning like that, check the docs. There you would see that NSArray doesn't respond to insertObject:atIndex:.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-07-2011, 12:12 PM   #3 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Unhappy

Hi,

I have used the NSMutableArray, but I still get an error. I have included the code for populating the array in case there is an issue with that as well.

My code is;
*.h
Code:
NSMutableArray *arryData;
*.m
Code:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
      toIndexPath:(NSIndexPath *)toIndexPath {
    
    NSString *item = [[arryData objectAtIndex:fromIndexPath.row] retain];
    [arryData removeObjectAtIndex:fromIndexPath.row];
    [arryData insertObject:item atIndex:toIndexPath.row];
    [item release];
}

- (void)viewDidLoad
{
    arryData = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil];
    [super viewDidLoad];
}
scrumsolutions is offline   Reply With Quote
Old 06-07-2011, 12:32 PM   #4 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 35
scrumsolutions is on a distinguished road
Wink

Quote:
Originally Posted by scrumsolutions View Post
Hi,

I have used the NSMutableArray, but I still get an error. I have included the code for populating the array in case there is an issue with that as well.

My code is;
*.h
Code:
NSMutableArray *arryData;
*.m
Code:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
      toIndexPath:(NSIndexPath *)toIndexPath {
    
    NSString *item = [[arryData objectAtIndex:fromIndexPath.row] retain];
    [arryData removeObjectAtIndex:fromIndexPath.row];
    [arryData insertObject:item atIndex:toIndexPath.row];
    [item release];
}

- (void)viewDidLoad
{
    arryData = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil];
    [super viewDidLoad];
}
Ignore me, I'm being a plank! I forgot to declare [[NSArray alloc], I forgot to change this to NSMutableArray!
scrumsolutions is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, reordering, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 323
6 members and 317 guests
chemistry, Dnnake, iOS.Lover, jenniead38, pbart, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0