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 07-18-2010, 06:34 PM   #1 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default tableView:moveRowAtIndexPath:toIndexPath:

I have an NSMutableArray holding Moving Files which load into the player depending on the cell indexPath. The retain method below does the job in retaining the cell, its title and the file all together when moved. Yet when I push a new view within UINavigation I retain is lost.

What is the best way to retain an array throughout the app when using tableView:moveRowAtIndexPath:toIndexPath:

My Array

Code:
if (filmMovie == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                                                 @"Mov1.mov", 
								 @"Mov2.mov", 
								 @"Mov3.mov", 
								 @"Mov4.mov", 
								 @"Mov5.mov", 
								 @"Mov6.mov", 
                                                                 @"Mov7.mov", 
								 @"Mov8.mov", 
								 @"Mov9.mov", 
								 @"Mov10.mov", nil];
        self.filmMovie = array;
        [array release];        
    }
My Retain

Code:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
    NSUInteger fromRow = [fromIndexPath row];
    NSUInteger toRow = [toIndexPath row];
    
    id object = [[filmMovie objectAtIndex:fromRow] retain];
    [filmMovie removeObjectAtIndex:fromRow];
    [filmMovie insertObject:object atIndex:toRow];
    [object release];
}
Thoughts?
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 06:51 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Your problem is not clearly stated. What is the issue?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 06:56 PM   #3 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Your problem is not clearly stated. What is the issue?
When tableCells are moved and rearranged all info assigned to each cell moves with it (Job done) yet when the view changes to another UIView or UITableview and one goes back to the table with the cells that have been rearranged none of the info assigned to the tableCell is right as the user left it. all TableCells go back to the original state.
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 06:58 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Where else do you mess with filmMovie?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 07:00 PM   #5 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Where else do you mess with filmMovie?
Only here to populate the Cell Button for which Movie will be played...

Code:
/*---------------------------------------------------------------------------
 * MoviePlayer
 *--------------------------------------------------------------------------*/

- (void)buttonMethod:(UIButton *)sender {
	
	NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
	
	NSInteger section = indexPath.section;
	NSInteger row = indexPath.row;
	NSString *rowTitle = [filmMovie objectAtIndex:row];
	
	NSLog(@"Button is in section %d and row %d", section, row);
	
	//for getting cell
	//UITableViewCell *cell = (UITableViewCell *)[sender superview];

	NSString *path = [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil];
	
	// Create custom movie player   
	moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];
	
	// Show the movie player as modal
	[self presentModalViewController:moviePlayer animated:YES];
	
	// Prep and play the movie
	[moviePlayer readyPlayer];
}
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:02 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok, how do you go to/from another view?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 07:05 PM   #7 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Ok, how do you go to/from another view?
Button on the UIToolbar just like an info button...

Code:
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SettingsIcon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(pushInfoView:)];
Button...

Code:
-(void) pushInfoView:(id)sender {
	UINavigationController *navController = self.navigationController;
	InfoViewController *viewOne = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
	[navController pushViewController:viewOne animated:YES];
}
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:06 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Do you accidentally have:

Code:
if (filmMovie = nil)
...where you build the array? If not, post that entire method.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 07:10 PM   #9 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Do you accidentally have:

Code:
if (filmMovie = nil)
...where you build the array? If not, post that entire method.
.h

Code:
@interface AllFilmController : SecondLevelViewController <AVAudioPlayerDelegate> {
	
	CustomMoviePlayerViewController *moviePlayer;
	NSMutableArray *filmTitle;
	NSMutableArray *filmDescription;
	NSMutableArray *filmTime;
	NSMutableArray *filmSound;
	NSMutableArray *filmMovie;
	AVAudioPlayer *theAudio;
	UIButton *buttonMethod;
	UIToolbar *toolbar;
}
@property (nonatomic, retain) NSMutableArray *filmTitle;
@property (nonatomic, retain) NSMutableArray *filmDescription;
@property (nonatomic, retain) NSMutableArray *filmTime;
@property (nonatomic, retain) NSMutableArray *filmSound;
@property (nonatomic, retain) NSMutableArray *filmMovie;
@property (nonatomic,retain) AVAudioPlayer* theAudio;
-(void) toggleMove:(id)sender;
-(void) pushInfoView:(id)sender;
-(void)buttonMethod:(UIButton *)sender;

@end
.m

Code:
@synthesize filmTitle, filmDescription, filmTime, filmSound, filmMovie;
Code:
/*---------------------------------------------------------------------------
 * ViewDidLoad
 *--------------------------------------------------------------------------*/

- (void)viewDidLoad {
    if (filmTitle == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"Title1", 
								 @"Title2", 
								 @"Title3", 
								 @"Title4", 
								 @"Title5", 
								 @"Title6", 
                                 @"Title7", 
								 @"Title8", 
								 @"Title9", 
								 @"Title10", nil];
        self.filmTitle = array;
        [array release];        
    }
	
	if (filmDescription == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"Description1", 
								 @"Description2", 
								 @"Description3", 
								 @"Description4", 
								 @"Description5", 
								 @"Description6", 
                                 @"Description7", 
								 @"Description8", 
								 @"Description9", 
								 @"Description10", nil];
        self.filmDescription = array;
        [array release];        
    }
	
	if (filmTime == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"0.01s", 
								 @"0.02s", 
								 @"0.03s", 
								 @"0.04s", 
								 @"0.05s", 
								 @"0.06s", 
                                 @"0.07s", 
								 @"0.08s", 
								 @"0.09s", 
								 @"0.10s", nil];
        self.filmTime = array;
        [array release];        
    }
	
	if (filmSound == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"SLJ1.aif", 
								 @"SLJ2.aif", 
								 @"SLJ3.aif", 
								 @"SLJ4.aif", 
								 @"SLJ5.aif", 
								 @"SLJ6.aif", 
                                 @"SLJ7.aif", 
								 @"SLJ8.aif", 
								 @"SLJ9.aif", 
								 @"SLJ10.aif", nil];
        self.filmSound = array;
        [array release];        
    }
	
	if (filmMovie == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"Mov1.mov", 
								 @"Mov2.mov", 
								 @"Mov3.mov", 
								 @"Mov4.mov", 
								 @"Mov5.mov", 
								 @"Mov6.mov", 
                                 @"Mov7.mov", 
								 @"Mov8.mov", 
								 @"Mov9.mov", 
								 @"Mov10.mov", nil];
        self.filmMovie = array;
        [array release];        
    }
	
	// Configure the table view.
    self.tableView.rowHeight = kTableViewRowHeight;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
	self.tableView.backgroundColor = kTableViewBackground;
	self.tableView.opaque = NO;
	
    [super viewDidLoad];
}
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:16 PM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Still not seeing it.

There are really only two possibilities:

1. You are doing something to reset the array. viewDidLoad should really only fire again if you run out of memory in a later view controller, and the array property would have to be nil in order for the array to be recreated. Should be easy enough to tell if that is happening.

2. You are incorrectly coming back to this view controller from the other views. Perhaps you are making a new view controller instead of returning to this one. So you aren't seeing incorrect data, you are seeing new data.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 07:23 PM   #11 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

OK
__________________
Follow Me on Twitter

Last edited by CeiJay; 07-19-2010 at 07:27 AM.
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:26 PM   #12 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

filmViewController.m (Part 1)
__________________
Follow Me on Twitter

Last edited by CeiJay; 07-19-2010 at 07:28 AM.
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:27 PM   #13 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

Thinking
__________________
Follow Me on Twitter

Last edited by CeiJay; 07-19-2010 at 07:28 AM.
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:48 PM   #14 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

You are right..

I have the FirstLevelViewController which when a cell is tapped loads the AllFilmController through the SecondLevelViewController. If I move Cells within the AllFilmController and the go back to the FirstLevelViewController then Exit the App and Reenter, tapped the same cell to go to the AllFilmController then everything is as I left it. Yet When I touch this Info Button on the Toolbar to load a UIView and go back the I look the Users Changes. Likewise when a movie loads via MoviePlayerViewController the same happens.

Looking in to it. Any extra pointers in the right direction would be great.
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Old 07-18-2010, 07:58 PM   #15 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok, 3 possibilities: you may not be changing the array. This can't possibly work, can it?

Code:
id object = [[filmTitle, filmDescription, filmTime, filmSound, filmMovie objectAtIndex:fromRow] retain];
[filmTitle, filmDescription, filmTime, filmSound, filmMovie removeObjectAtIndex:fromRow];
[filmTitle, filmDescription, filmTime, filmSound, filmMovie insertObject:object atIndex:toRow];
[object release];
How can a single variable - object - refer to five objects at the same time? I would be shocked and amazed if this actually worked.

Other observations:

1. You REALLY need a custom Film model object. That way you could have one array instead of 5.

2. Navigation controllers already have a toolbar.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-18-2010, 08:03 PM   #16 (permalink)
Registered Member
 
CeiJay's Avatar
 
Join Date: May 2010
Posts: 21
CeiJay is on a distinguished road
Default

OK, great, thank you - I will work on this and make the changes. Much appreciated
__________________
Follow Me on Twitter
CeiJay is offline   Reply With Quote
Reply

Bookmarks

Tags
moverowatindexpath, moving, nsarray, retain, 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: 331
14 members and 317 guests
akphyo, alexP, appservice, bignoggins, EXOPTENDAELAX, flamingliquid, guusleijsten, Hamad, mariano_donati, ohmniac, Paul Slocum, Rudy, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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