Delete or clear ALL data objects in UITableView with alert button?

OK, I really have searched through the topics that seem to cover this but still have not found one that works for me. This list is made by sending every UIWebView page load here. At some point if the user would like to clear this list I have a button that brings up an alert view that just confirms that they want to clear and then press OK to clear. Please, tell me how I can do this. About halfway down you can find my clearAllData which is clearAllRecents alert button but my void function underneath that is my ?

#import "RecentViewController.h"
#import "ViewController.h"

@interface RecentViewController ()

@end

@implementation RecentViewController

@synthesize recent, explorerView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    recent = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"Recent"] mutableCopy];
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (IBAction)cancelButtonTapped
{
    [self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self.presentingViewController dismissModalViewControllerAnimated:true];
}

- (IBAction)clearAllRecents
{
    UIAlertView *alert = [[UIAlertView alloc] 
                      initWithTitle:@"clear all recents?"
                      message:@"press ok to clear"
                      delegate: self
                      cancelButtonTitle:@"cancel"
                      otherButtonTitles:@"ok", nil];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        //clear all recent objects??????????????????????????????????????????????
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [recent count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyle)UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.textLabel.text = [recent objectAtIndex:(recent.count - indexPath.row - 1)];
    cell.textLabel.textColor = [UIColor whiteColor];;
    cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:20.0];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    explorerView.urlField.text = [recent objectAtIndex:(recent.count - indexPath.row - 1)];
    [explorerView textFieldShouldReturn:explorerView.urlField];
    [self.presentingViewController dismissModalViewControllerAnimated:true];
    explorerView = nil;
    recent = nil;
    tableView = nil;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [recent removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
        [[NSUserDefaults standardUserDefaults] setObject:recent forKey:@"Recent"];
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Answers


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex      {

if (buttonIndex == 1) {
    [recent removeAllObjects];
    [[NSUserDefaults standardUserDefaults] setObject:recent forKey:@"Recent"];
    [yourTableView reloadData];
}}

That should do it.


Need Your Help

Does Presto support RC file with snappy compression?

prestodb

Trying to read snappy compressed table using Presto on CDH4 cluster.

Add to a PHP variable on GET

php get google-cloud-messaging

This PHP file that sends a push GCM

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.