views:

7

answers:

0

Can someone help me? I made an action 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, th 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:

        - (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

#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