10-14-2010, 10:38 AM
#1 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 18
TableView ReloadData not working after action
Can someone help me? I made an uialertview with prompt to rename items in my uitableview. The table view is populated with videos located in a directory. The problem is when I try to rename a file, the reloaddata do not work. I need to tap on my first tab and come back to the second tab to see the change.
This is what I have:
Quote:
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"viewDidAppear");
directoryContent = (NSMutableArray *) [[[[NSFileManager defaultManager] directoryContentsAtPath:@"/my/path/to/mp4/files"]
pathsMatchingExtensions:[NSArray arrayWithObjects:@"MP4", @"mp4", nil]] retain];
[self.tableView reloadData];
[super viewDidAppear:animated];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.editing == YES) {
AlertPrompt *prompt = [AlertPrompt alloc];
prompt = [prompt initWithTitle:@"Rename the video:" message:@"Don't need extension" delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Rename"];
[prompt show];
[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[prompt release];
}
else {
.... my codes to play the videos with MediaPlayer framework....
}
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *entered = [(AlertPrompt *)alertView enteredText];
NSLog(@"String entered is: %@", entered);
entered = [[entered stringByAppendingString:@".mp4"] retain];
NSLog(@"String entered and mp4 is: %@", entered);
NSFileManager *defaultManager;
defaultManager = [NSFileManager defaultManager];
NSString *anotherPath = [NSString stringWithFormat:@"/my/path/to/mp4/files/%@", selectedVideo];
NSString *anotherAnotherPath = [NSString stringWithFormat:@"/my/path/to/mp4/files/%@", entered];
NSError *error1;
if ([defaultManager moveItemAtPath:anotherPath toPath:anotherAnotherPath error:&error1]) {
[self refreshTable];
}
else {
//NSString *str = [NSString stringWithFormat:@"%@",error1];
NSDictionary *dict = [error1 userInfo];
NSInteger int1 = [error1 code];
NSString *str = [dict description];
NSLog(@"%@ and Code is %i and domain is %@",str,int1,[error1 domain]);
[self refreshTable];
}
}
else {
}
[self refreshTable];
}
- (void)refreshTable {
[self.tableView reloadData];
}
AlertPrompt.h
Quote:
#import "AlertPrompt.h"
@implementation AlertPrompt
@synthesize textField;
@synthesize enteredText;
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{
if (self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
{
UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(22.0, 45.0, 240.0, 25.0)];
[theTextField setBackgroundColor:[UIColor whiteColor]];
[self addSubview:theTextField];
self.textField = theTextField;
[theTextField release];
//CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 130.0);
//[self setTransform:translate];
}
return self;
}
- (void)show
{
[textField becomeFirstResponder];
[super show];
}
- (NSString *)enteredText
{
return textField.text;
}
- (void)dealloc
{
[textField release];
[super dealloc];
}
@end
Thank you
10-14-2010, 02:55 PM
#2 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
Look at what you are doing in viewDidAppear:. Now compare to refreshTable. Notice anything?
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
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38