好的,我真的已经搜索了似乎涵盖这一点的主题,但仍然没有找到适合我的主题。此列表是通过将每个 UIWebView 页面加载发送到此处来制作的。在某些时候,如果用户想清除此列表,我有一个按钮,它会显示一个警报视图,确认他们想要清除,然后按 OK 清除。请告诉我我该怎么做。大约在中途您可以找到我的 clearAllData,它是 clearAllRecents 警报按钮,但我下面的 void 函数是 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