07-18-2010, 06:34 PM
#1 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
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?
07-18-2010, 06:51 PM
#2 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
Your problem is not clearly stated. What is the issue?
07-18-2010, 06:56 PM
#3 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
Quote:
Originally Posted by
BrianSlick
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.
07-18-2010, 06:58 PM
#4 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
Where else do you mess with filmMovie?
07-18-2010, 07:00 PM
#5 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
Quote:
Originally Posted by
BrianSlick
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];
}
07-18-2010, 07:02 PM
#6 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
Ok, how do you go to/from another view?
07-18-2010, 07:05 PM
#7 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
Quote:
Originally Posted by
BrianSlick
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];
}
07-18-2010, 07:06 PM
#8 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
Do you accidentally have:
Code:
if (filmMovie = nil)
...where you build the array? If not, post that entire method.
07-18-2010, 07:10 PM
#9 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
Quote:
Originally Posted by
BrianSlick
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];
}
07-18-2010, 07:16 PM
#10 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
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.
07-18-2010, 07:23 PM
#11 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
OK
Last edited by CeiJay; 07-19-2010 at 07:27 AM .
07-18-2010, 07:26 PM
#12 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
filmViewController.m (Part 1)
Last edited by CeiJay; 07-19-2010 at 07:28 AM .
07-18-2010, 07:27 PM
#13 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
Thinking
Last edited by CeiJay; 07-19-2010 at 07:28 AM .
07-18-2010, 07:48 PM
#14 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
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.
07-18-2010, 07:58 PM
#15 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
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.
07-18-2010, 08:03 PM
#16 (permalink )
Registered Member
Join Date: May 2010
Posts: 21
OK, great, thank you - I will work on this and make the changes. Much appreciated
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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