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 10-14-2010, 10:38 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 18
bobby456 is on a distinguished road
Default 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
bobby456 is offline   Reply With Quote
Old 10-14-2010, 02:55 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

Look at what you are doing in viewDidAppear:. Now compare to refreshTable. Notice anything?
__________________
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
Reply

Bookmarks

Tags
reloaddata, rename, uialertview, 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: 350
7 members and 343 guests
Desert Diva, dre, hain, HemiMG, lendo, mottdog, oceanlablight
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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