Display an alert on Swipe Delete in iOS - ios

I'm a beginner in iOS. I'm performing a swipe delete option. I want to display an alert view before deleting the row. How can i perform this action.
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"%#",collisionsArray);
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
NSString *userId = [userinfo valueForKey:#"user_id"];
if(userId!=nil)
{
NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
collisionId = [NSString stringWithFormat:#"%#",[dict valueForKey:#"collisionId"]];
NSLog(#"%#",collisionId);
// removes saved datas from database
BOOL result = [database removeCollisionDetails:collisionId:#"accident_report"];
if(result)
{
[[SHKActivityIndicator currentIndicator]
displayCompleted:NSLocalizedString(#"val_sucess_vehicle", nil)];
[self.navigationController popViewControllerAnimated:YES];
}
else
{
[[SHKActivityIndicator currentIndicator]
displayCompleted:NSLocalizedString(#"val_error", nil)];
}
}
}
[self.tableView reloadData];
}

For this you can just display an alet view in:
if (editingStyle == UITableViewCellEditingStyleDelete){
// Show your alert view
// Set its delegate to self
}
Now you have to do something like:
#pragma mark ---- Delegate for alertview ----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
NSString *userId = [userinfo valueForKey:#"user_id"];
if(userId!=nil)
{
NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
collisionId = [NSString stringWithFormat:#"%#",[dict valueForKey:#"collisionId"]];
NSLog(#"%#",collisionId);
// removes saved datas from database
BOOL result = [database removeCollisionDetails:collisionId:#"accident_report"];
if(result)
{
[[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(#"val_sucess_vehicle", nil)];
[self.navigationController popViewControllerAnimated:YES];
}
else
{
[[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(#"val_error", nil)];
}
}
}

-(void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Warring" message:#"Are You Sure?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes ", nil];
[alert show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
}else if (buttonIndex == 1){
NSIndexPath *indexPath=[_UserTableView indexPathForSelectedRow];
[showUData removeObjectAtIndex:indexPath.row]; //showUData NSMutableArray
[_UserTableView reloadData];
[storeData setObject:showUData forKey:#"SendData"]; //storeData NSUserDefault
[storeData synchronize];
}
}

Use UIAlertView and only delete if the user confirms. Update your code to :
if (editingStyle == UITableViewCellEditingStyleDelete)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"Are you sure ?"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
Implement the UIAlertViewDelegate and move the original delete code to the delegate method where you detect which button has been tapped.

Related

Whenever I try to save a NSUserDefualts to a NSMutableArray it crashes

I've been using NSUserDefualts. Whenever I try to save to a NSMutableArray it crashes the app. How would I fix this?
I tried to figure it out online, but it's been bringing up either swift or guides that don't support any of what I searched.
#import "scoutViewViewController.h"
#interface scoutViewViewController ()
#property (weak, nonatomic) IBOutlet UITableView *scoutView;
#end
BOOL check = YES;
#implementation scoutViewViewController
*tableData; // u need this for a standalone/ static one
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
tableData =[[NSUserDefaults standardUserDefaults] objectForKey:#"data_0"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
//segue select
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"show" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"show"]) {
}
}
//ediatable tableView
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self scoutView];
}
}
- (IBAction)addCell:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Team Name Or Number" message: #"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//only accept if the user hit ok
// need to implement "UIAlertController" becuase UIAlert is no longer used.
if(buttonIndex == 1){
NSString *temptxtfield = [alertView textFieldAtIndex:0].text;
if(!tableData){
tableData = [[NSMutableArray alloc]init];
}
if([temptxtfield isEqual: #""] || [temptxtfield isEqual: #" "]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Team Name Or Number" message: #"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
check = NO; //check, nothing to do wiht the implemtaiont
}else{
check = YES;//check, nothing to do wiht the implemtaiont
}
if(check == YES){//check, nothing to do wiht the implemtaiont
[tableData insertObject:temptxtfield atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.scoutView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
check= NO;//check, nothing to do wiht the implemtaiont
}//check, nothing to do wiht the implemtaiont
//check is to prevent nothing to be placed into the tabel, nothing to do with how the data is inserted into the table
}
}
- (IBAction)saveTable:(id)sender {
[[NSUserDefaults standardUserDefaults] setObject: tableData forKey:#"data_0"];
}
-(void)save2{
}
#end
It gives me a SIGBART error when it crashes, I tried figuring out with break points but it's being a pain.
ended up figuring it out, pretty simple now that I think of it and I feel pretty dumb not knowing it beofore lol...
tableData = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"tabelSave"]];

Display alert if no recipients are selected iOS

I have a page where we select recipients (who are friends) to send an image to. but if no recipients are selected we can still send the message. i want it so that if no recipients are selected we can show a UIAlertView. for me its not working when i try to display an alert please see my code below.
.h
#property (nonatomic, strong) NSArray *friends;
#property (nonatomic, strong) PFRelation *friendsRelation;
#property (nonatomic, strong) NSMutableArray *recipients;
- (IBAction)send:(id)sender;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.recipients = [[NSMutableArray alloc] init];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.friendsRelation = [[PFUser currentUser] objectForKey:#"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:#"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(#"Error %# %#", error, [error userInfo]);
}
else {
self.friends = objects;
[self.tableView reloadData];
}
}];
//display camera modally etc......
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
cell.textLabel.text = user.username;
if ([self.recipients containsObject:user.objectId]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.recipients addObject:user.objectId];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[self.recipients removeObject:user.objectId];
}
NSLog(#"%#", self.recipients);
}
here is the part where i try to display my alert
- (IBAction)send:(id)sender {
if (!self.recipients) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Select some friends" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
[self uploadMessage];
//we upload the message in method to parse.com
}
}
it does not seem to show for some reason so we can send messages to no one. how can i show the alert view?
Try this. Check objects of recipients is equal to 0 or not.
- (IBAction)send:(id)sender {
if ([self.recipients count]==0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Select some friends" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
[self uploadMessage];
//we upload the message in method to parse.com
[self.tabBarController setSelectedIndex:1];
}
}
The problem with your code is the condition that you are checking::
if (!self.recipients)
here self.recipients will always give true value as it will look for memory address of this object, which you have assigned to it in your viewDidLoad method.
You have to check for the count of the array in your scenario.

Reload data after logging in

I have a left slide menu powered by AMSlideMenu library that displays a tableview with menu items.
AMSlideMenuLeftTableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:18];
cell.textLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([[NSUserDefaults standardUserDefaults] objectForKey:#"loggedUser"] != nil) {
if (indexPath.row == 0) { cell.textLabel.text = [NSString stringWithFormat:#"Hi, %#", [[NSUserDefaults standardUserDefaults] objectForKey:#"loggedUser"]]; }
if (indexPath.row == 1) { cell.textLabel.text = #"Contact"; }
} else {
if (indexPath.row == 0) { cell.textLabel.text = #"Log in"; }
if (indexPath.row == 1) { cell.textLabel.text = #"Contact"; }
}
}
LoginViewController.m
- (IBAction)loginButtonPressed:(id)sender {
if(![self.usernameTextField.text isEqual: #""] && ![self.passwordTextField.text isEqual:#""]){
for (UITextField *eachTextfield in self.view.subviews)
[eachTextfield resignFirstResponder];
PFQuery *query = [PFQuery queryWithClassName:#"UsersClass"];
[query whereKey:#"Username" equalTo:self.usernameTextField.text];
[query whereKey:#"Password" equalTo:self.passwordTextField.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
if (objects.count > 0){
[self dismissViewControllerAnimated:YES completion:nil];
//Get the username and save it as "loggedUser" for later use
[[NSUserDefaults standardUserDefaults] setObject:self.usernameTextField.text forKey:#"loggedUser"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self performSegueWithIdentifier:#"showDetail" sender:self];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:NSLocalizedString(#"The username or password are incorrect", nil) delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:NSLocalizedString(#"Both fields are required", nil) delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
However, after logging in, the menu does not refresh and keeps displaying the wrong cell.textLabel.text. It works if I close and open again the application, but obviously there has to be another way of solving this.
I have tried [tableView reloadData] but this does not work. I have tried it on viewDidLoad and viewWillAppear without success.
Appreciate any help. Thanks
Here is what you need to do. In your loginButtonPressed method in case of a successful login post a notification like this:
NSNotification *loginNotification = [NSNotification notificationWithName:#"USER_DID_LOGIN" object:nil];
[[NSNotificationCenter defaultCenter] postNotification:loginNotification];
In your view controller with tableView do this:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(updateOnLogin:) name:#"USER_DID_LOGIN" object:nil];
}
- (void)updateOnLogin:(NSNotification*)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
Whenever user logs in successfully, your view controller will receive a notification, and it will reload the tableView.

Custom added cell wont save in table view

I have a alert view with a textfield so whenever someone types in it and pressed the save button it puts in the table view. when you click on the cell after being saved it takes you to a different view. Now when you go back to the home page, the cells disappear. I have tried multiple ways of figuring it out, yet still haven't been able to. Do I need to add a plist so every time I add a cell it gets saved to the plist and if so where would i start?
This code is in my table view controller
- (IBAction)add:(id)sender {
NSLog(#"%#",tableData);
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"My Favs" message:#"Hello" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.enablesReturnKeyAutomatically = YES;
alertTextField.placeholder = #"example";
[alert show];
return;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"%#",tableData);
//Only do the following action if the user hits the ok button
if (buttonIndex == 1){
NSString *tapTextField = [alertView textFieldAtIndex:0].text;
if (!tableData)
{
tableData = [[NSMutableArray alloc]init];
}
[tableData insertObject:tapTextField atIndex:0];
[myTableView reloadData];
}
}
I think tableData is getting deallocated when you are coming back to the home page. If the tableData is not a huge array you can store it in NSUserDefaults. This way when ever you come back to the table you can always retreat the data. Check out this code. It will store the tableData in the NSUserDefaults every time you add anything to the array. Let me know if this works for you.
#import "ViewController.h"
#interface ViewController () <UIAlertViewDelegate,UITableViewDataSource,UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *myTableView;
#property (nonatomic,strong) NSMutableArray *tableData;
#end
#implementation ViewController
-(NSMutableArray *)tableData
{
if(!_tableData){
NSMutableArray *data = [[NSUserDefaults standardUserDefaults]objectForKey:#"data"];
if(!data){
_tableData = [[NSMutableArray alloc]init];
}else{
_tableData = [data mutableCopy];
}
}
return _tableData;
}
- (IBAction)add:(UIButton *)sender {
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"My Favs" message:#"Hello" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.enablesReturnKeyAutomatically = YES;
alertTextField.placeholder = #"example";
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1){
NSString *tapTextField = [alertView textFieldAtIndex:0].text;
[self.tableData insertObject:tapTextField atIndex:0];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:self.tableData forKey:#"data"];
[defaults synchronize];
[self.myTableView reloadData];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return[self.tableData count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"dataCell" forIndexPath:indexPath];
if(self.tableData.count > 0){
cell.textLabel.text = self.tableData[indexPath.row];
}
return cell;
}

Saving Method for a button

this is my code in my .m file
#interface HomeWorkViewController ()
#end
#implementation HomeWorkViewController
#synthesize adView;
#synthesize myTableView, numbers;
-(void) viewDidLoad
{
adView.delegate=self;
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
// check here if key exists in the defaults or not, if yes the retrieve results in array
if([[NSUserDefaults standardUserDefaults] objectForKey:#"numberArray"] != nil) {
self.numbers = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"numberArray"]];
}
//Register for the notification when user go to background or minimize the app, just save the array objects in the defaults
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(appWillGoToBackground:)
name:UIApplicationWillResignActiveNotification
object:[UIApplication sharedApplication]];
//Add the Add button
UIBarButtonItem * addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target: self action: #selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.myTableView setEditing:editing animated:animated];
}
-(void)appWillGoToBackground:(NSNotification *)note {
NSLog(#"terminate");
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.numbers forKey:#"numberArray"];
[defaults synchronize];
}
-(void)insertNewObject{
//Display a UIAlertView
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Enter HomeWork" message: #"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Only perform the following actions if the user hits the ok button
if (buttonIndex == 1)
{
NSString * tmpTextField = [alertView textFieldAtIndex:0].text;
if(!self. numbers){
self.numbers = [[NSMutableArray alloc]init];
}
[self.numbers insertObject:tmpTextField atIndex:0];
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.myTableView insertRowsAtIndexPaths:#[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.numbers.count;
}
-(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];
}
cell.textLabel.text = [self.numbers objectAtIndex:indexPath.row];
return cell;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//remove our NSMutableArray
[self.numbers removeObjectAtIndex:indexPath.row];
//remove from our tableView
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
adView.hidden=FALSE;
NSLog(#"Has ad, showing");
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
adView.hidden=TRUE;
NSLog(#"Has no ads, hiding");
}
-(void)dealloc
{
[adView release];
[super dealloc];
}
#end
I have a saving method there but I want to save everything that I changed in the table by clicking a button. How do i do that?
I want to put a toolbar with a button that says back to go to the home screen, and link this button to save everything that was done to the table like delete, switch order and add.
You're almost there :)
You are using the numbers array as the data model for the table.
Make sure that this array is always updated when the table is manipulated. (For example, you need to reorder the numbers array in moveRowAtIndexPath. Currently, you do nothing in that method)
To save the model using a button, just create a UIButton in the Interface Builder and connect it to the following action:
- (IBAction)saveButtonWasPressed:(id)sender {
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.numbers forKey:#"numberArray"];
[defaults synchronize];
}
Maybe you also want to pop the tableviewcontroller from the navigationcontroller stack if you also want to leave the controller.

Resources