I have this code
And this code in my method
I want that whenever i press the Button i am creating in the Cell , the table should update and refresh or may be reload the data from the array. I have tried [self.tableView reloadData] but its not working for me. Where and how should i use the method to refresh my TableView on Button Click
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
NSUInteger row = [indexPath row];
NSString *objectGotFromRow = [data objectAtIndex:row];
if ([objectGotFromRow hasPrefix:@"."])
{
UIImage *buttonUpImage = [UIImage imageNamed:@"Unhide.png"];
UIImage *buttonDownImage = [UIImage imageNamed:@"Unhide.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonUpImage.size.width,
buttonUpImage.size.height);
[button setBackgroundImage:buttonUpImage
forState:UIControlStateNormal];
[button setBackgroundImage:buttonDownImage
forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(unHideButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
}
}
// Configure the cell.
NSUInteger row = [indexPath row];
NSString *objectGotFromRow = [data objectAtIndex:row];
cell.textLabel.text = objectGotFromRow;
return cell;
}
And this code in my method
Code:
- (IBAction)hideButtonPressed:(id)sender
{
UIButton *senderButton = (UIButton *)sender;
UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview];
NSUInteger buttonRow = [[self.tableView indexPathForCell:buttonCell] row];
NSString *buttonTitle = [data objectAtIndex:buttonRow];
NSString *path = @"/Some/Path/";
NSString *unhiddenPath = [path stringByAppendingString:buttonTitle];
NSString *pathForHiddenString = @"/Some/Path/";
NSString *hiddenPath = [pathForHiddenString stringByAppendingString:buttonTitle];
NSString *contents = [fileManager directoryContentsAtPath:path];
NSString *msg = [[NSString alloc] initWithFormat:@"File named %@ is now hidden",buttonTitle];
if ([fileManager moveItemAtPath:unhiddenPath toPath:hiddenPath error:nil])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"File hidden !!!" message:msg delegate:nil cancelButtonTitle:@"Ya i know !!!" otherButtonTitles:nil];
[alert show];
[alert release];
[B][self.tableView reloadData];[/B]
[msg release];
}
}
I want that whenever i press the Button i am creating in the Cell , the table should update and refresh or may be reload the data from the array. I have tried [self.tableView reloadData] but its not working for me. Where and how should i use the method to refresh my TableView on Button Click