iOS: button in UITableViewCell class to call method on main UIViewController - iphone

I have a UITableView on my MainViewController which has custom UITableCells defined in a CustomCell class. I need an UIButton, which is in my CustomCell class, to call a method in MainViewController. I cannot create a new instance of MainViewController because the method uses some variables which would all be in the default state if I created a new instance. What do I do??
This is my code:
MainViewController.m (this is the method I want called):
-(void)updateLabels{
double totalValue=0, personValue=0;
[self returnTickArray];
for(NSInteger i = 0; i < n; i++) {
totalValue += ([[[self returnPricesArray] objectAtIndex:i] doubleValue] * [[[self returnQtyArray] objectAtIndex:i]doubleValue]);
if([[[self returnPeopleArray] objectAtIndex:i]doubleValue]>0) personValue += ([[[self returnPricesArray] objectAtIndex:i] doubleValue] * [[[self returnQtyArray] objectAtIndex:i]doubleValue]/ [[[self returnPeopleArray] objectAtIndex:i]doubleValue] * [[[self returnTickArray] objectAtIndex:i]doubleValue]);
}
_totalValue.text = [NSString stringWithFormat:#"$ %.02lf", totalValue];
_tip.text= [NSString stringWithFormat:#"$ %.02lf", totalValue*(([_tipPercentage.text doubleValue]/100))];
_addedValue.text= [NSString stringWithFormat:#"$ %.02lf",([[_tip.text substringFromIndex:2] doubleValue]+totalValue) ];
_perPerson.text=[NSString stringWithFormat:#"$ %.02lf", personValue];
}
This is the method in CustomCell.m which gets called when I press the button:
- (IBAction)tick:(UIButton *)sender {
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:#"off"] forState:UIControlStateNormal];
[sender setSelected:NO];
_isTicked = [NSNumber numberWithInt:0];
}
else {
[sender setImage:[UIImage imageNamed:#"on"] forState:UIControlStateSelected];
[sender setSelected:YES];
_isTicked = [NSNumber numberWithInt:1];
}
}

you can assign a method from your controller to a button from UITableView in your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method
[cell.yourButton addTarget:self action:#selector(updateLabels) forControlEvents:UIControlEventTouchUpInside];
(just don't forget to add IBOutlet of your button to your custom cell class)

Handling changes, actions, or user interaction in other views is the essential use case of delegates. The best practice is to have the MainViewController be the delegate of the CustomCell, and then as events happen in the cell (i.e., tick is called), it calls certain methods on its delegate to notify it and the delegate then calls updateLabels.
Other options for keeping values/state in sync between views are:
Core Data - best used for data
Key-Value Observation - best used for data
NSNotifications sent through NSNotificationCenter - best used for actions

interesting :)
You need to use [UIApplication sharedApplication] singleton to process this.
Here are few steps:
Create object of MainViewController In you AppDelegate class:
in AppDelegate.h import MainViewController.h
#interface AppDelegate
{
MainViewController *mvc;
}
#property (strong) MainViewController *mvc;
in MainViewController.m
#implementation AppDelegate
#synthesize mvc =_mvc
Now come to your CustomCell.m
- (IBAction)tick:(UIButton *)sender {
[[(AppDelegate *)[[UIApplication sharedApplication] delegate] hvc] tick:sender];
}
Here you are seeing a method is called- tick_fromCell:. Now you have to define this method in your MainViewController class' .h ans .m files.
in MainViewController.h
-(void)tick:(id)sender;
and in MainViewController.m
-(void)tick:(id)sender {
NSLog("Clicking from my CustomCell :)");// Here you will put updateLabels method
[self updateLabels];
}

Related

sending data from DetailViewController to MasterViewController

This is what exactly I'm trying to do.
wizardviewcontroller.m
- (IBAction)onCountryClick:(id)sender {
MJDetailViewController *detailViewController = [[MJDetailViewController alloc] initWithNibName:#"MJDetailViewController" bundle:nil];
[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideLeftRight];
}
User click country button a popup shows with list.
when user select a row button title should change.
This is my detailview,
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
WizardViewController *mj = [[WizardViewController alloc] initWithNibName:#"WizardViewController" bundle:nil];
mj.countryselected = [countryNames objectAtIndex:indexPath.row];
[mj.countryButton setTitle:mj.countryselected forState:UIControlStateNormal];
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}
DetailViewController is dismissing, but countryButtonTitle is not updating. I know this is because the wizardview is not refreshing. I would like to know the correct workaround in this case.
Hope this helps to get better answer.
Make Protocol in MJDetailViewController
#protocol MJDetailViewControllerDelegate;
#interface MJDetailViewController : UIViewController
#property (nonatomic,assign) id< MJDetailViewControllerDelegate> delegate;
#end
#protocol MJDetailViewControllerDelegate <NSObject>
- (void)selectedContry:(NSString *)title;
#end
And call like
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
NSString *title = [countryNames objectAtIndex:indexPath.row];
if ([self.delegate respondsToSelector:#selector(selectedContry:)]) {
[self.delegate selectedContry:title];
}
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}
Add MJDetailViewControllerDelegate as a protocol in WizardViewController.h)
Now implement selectedContry: method in WizardViewController.m like:
- (void)selectedContry:(NSString *)title
{
[self.countryButton setTitle:title forState:UIControlStateNormal];
}
Hope it helps you.

How can i implemented delete button in AQGridViewCell

i want to add button in my Customized AQGridViewCell with ImageView. when i Click Edit button its showing delete button on the ImageGridViewCell like below image.i added delete button in cellForItemAtIndex method. here my code
- (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index
{
static NSString *photoCellIdentifier = #"IBImageGridViewCell";
IBImageGridViewCell *cell = (IBImageGridViewCell *)[self.gridView dequeueReusableCellWithIdentifier:photoCellIdentifier];
if (cell == nil) {
cell = [[IBImageGridViewCell alloc] initWithFrame:CGRectMake(3.0, 3.0, 100.0, 120.0) reuseIdentifier:photoCellIdentifier];
cell.selectionStyle = AQGridViewCellSelectionStyleNone;
}
PTKEntry *entry = [_objects objectAtIndex:index];
UIButton *deletebutton = [UIButton buttonWithType:UIButtonTypeCustom];
[deletebutton addTarget:self
action:#selector(deleteimage:)
forControlEvents:UIControlEventTouchDown];
[deletebutton viewWithTag:index];
deletebutton.frame = CGRectMake(70,0,30,30);
UIImage * buttonImage = [UIImage imageNamed:#"delete.png"];
[deletebutton setImage:buttonImage forState:UIControlStateNormal];
if (self.gridView.editing) {
deletebutton.hidden=NO;
}
else{
deletebutton.hidden=YES;
}
[cell.contentView addSubview:deletebutton];
[cell.contentView bringSubviewToFront:deletebutton];
if (entry.data && entry.data.photo) {
cell.imageView.image = entry.data.photo;
NSLog(#"load table");
} else {
cell.imageView.image = nil;
NSLog(#"Not load table");
}
return cell;
}
when the view loading didn't show delete button. and while click delete button it showing delete for each grid cell and click done button that delete button didn't hidden from my grid View cell view here
You can create delegate method in AQGridView and implement it in your class like
-(void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
This a delegate method approach.
If you create delegate method
-(void) gridView:(AQGridView *)argGridView deleteCell:(AQGridViewCell *)cell atIndex:(NSUInteger)index;
This will get invoked as didSelectItemAtIndex: when you click on delete button.
To do this follow this procedure.
Add a method canHideDelete: to show and hide delete button in your custom cell IBImageGridViewCell.
When you click on a specified cell then [cell canHideDelete:NO] to show delete button.
In your IBImageGridViewCell,
you can create a block to delete a specified cell.
To do this,
create an extension AQGridViewCell_Extension.h to AQGridViewCell like
#import "AQGridViewCell.h"
typedef void(^AQGridViewCellDeleteBlock)(AQGridViewCell*);
#interface AQGridViewCell ()
#property(nonatomic, copy) AQGridViewCellDeleteBlock deleteBlock;
#end
import "AQGridViewCell_Extension.h" in IBImageGridViewCell.m and AQGridView.m
Now, create a selector to handle delete button and call a block to delete cell.
-(void)deleteButtonAction
{
self.deleteBlock(self);
}
Create a delegate method to be implemented in your class to delete cell
Add this to AQGridView.h under #protocol AQGridViewDelegate
-(void) gridView:(AQGridView*) gridView deleteCell:(AQGridViewCell*) cell atIndex:(NSUInteger) index;
Now, in AQGridView.m,
change method
- (AQGridViewCell *) createPreparedCellForIndex: (NSUInteger) index usingGridData: (AQGridViewData *) gridData
{
[UIView setAnimationsEnabled: NO];
AQGridViewCell * cell = [_dataSource gridView: self cellForItemAtIndex: index];
cell.separatorStyle = _flags.separatorStyle;
cell.editing = self.editing;
cell.displayIndex = index;
cell.frame = [self fixCellFrame: cell.frame forGridRect: [gridData cellRectAtIndex: index]];
if ( _backgroundView.superview == self )
[self insertSubview: cell aboveSubview: _backgroundView];
else
[self insertSubview: cell atIndex: 0];
[UIView setAnimationsEnabled: YES];
__block AQGridView *localAQGridView = self;
// DELETE BUTTON BLOCK - TO CALL DELEGATE METHOD
cell.deleteBlock = ^(AQGridViewCell *argCell)
{
NSInteger index = [localAQGridView indexForCell:argCell];
//NSLog(#"Cell to be deleted is %d", index);
[localAQGridView.delegate gridView:localAQGridView deleteCell:argCell atIndex:index];
};
return ( cell );
}
Implement following method to delete a cell in your class
-(void) gridView:(AQGridView *)argGridView deleteCell:(AQGridViewCell *)cell atIndex:(NSUInteger)index
{
NSLog(#"ON deleting cell at %d", index);
[mediaItemsArray removeObjectAtIndex:index];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
[argGridView beginUpdates];
[argGridView deleteItemsAtIndices:indexSet withAnimation:AQGridViewItemAnimationFade];
[argGridView endUpdates];
}
I hope this helps you.
Another way of doing it without modifying the AQGridView class
Add a delete button in your IBImageGridViewCell.xib file and Modify your IBImageGridViewCell.h as
#class IBImageGridViewCell;
#protocol CustomGridCellViewDelegate<NSObject>
#optional
-(void) onDeleteButtonTouched:(IBImageGridViewCell *)sender;
#end
#interface IBImageGridViewCell : AQGridViewCell
+ (id) cellFromNib;
#property (nonatomic,assign) id <CustomGridCellViewDelegate> delegate;
#property (nonatomic, readonly, retain) IBOutlet UIView *contentView;
#property (weak, nonatomic) IBOutlet UIButton *deleteButton;
#property (nonatomic, copy) NSString *reuseIdentifier;
- (IBAction)deleteButtonAction:(UIButton *)sender;
#end
In your IBImageGridViewCell.m file add
- (IBAction)deleteButtonAction:(UIButton *)sender
{
[self.delegate onDeleteButtonTouched:self];
}
Now in your mainViewController.h add the delegate
#interface mainViewController : UIViewController<CustomGridCellViewDelegate>
In your mainViewController.m file
In the method
- (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index
Add
cell.delegate=self;
cell.deleteButton.tag =index;
Handle the delete button action
-(void)onDeleteButtonTouched:(NTGridViewCell *)sender
{
NSLog(#"Selected Button:%d",sender.deleteButton.tag);
[yourArrayList removeObjectAtIndex:sender.deleteButton.tag];
[self.gridView reloadData];
//***Animated delete
// [yourArrayList removeObjectAtIndex:sender.deleteButton.tag];
// NSIndexSet* set = [NSIndexSet indexSetWithIndex:sender.deleteButton.tag];
// [self.gridView beginUpdates];
// [self.gridView deleteItemsAtIndices:set withAnimation:AQGridViewItemAnimationFade];
// [self.gridView endUpdates];
}

How to pass/send the number of selected row in UITableViewController to another class?

Dudes, i'm having some trouble here in XCODE4.5 and I hope you can help me!
How can I pass or send the integer value of the selected row in UITableViewController to another ViewController, using the method didSelectRowAtIndexPath?
Here is my code :
SecondViewController.h
{
NSInteger myInteger;
}
#property(nonatomic) NSInteger myInteger;
SecondViewControl.m
-(void)viewDidLoad {
NSLog(#" the number is = %d",myInteger); //this is not working, I always get "the number is = 0 "
}
FirstViewController.h
#import "SecondViewController"
//...
FirstViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath) {
NSIndexPath *path = indexPath;
NSInteger theInteger = path.row;
NSLog(#"selected row = %d", theInteger); //code OK
//THE PROBLEM STARTS HERE!!!!!!!!!!!!!!!!!!
SecondViewController *second = [[SecondViewController alloc]init];
[second setMyInteger:theInteger];
// i'm trying to use "second.myInteger = theInteger;" , but it's also not working
}
}
Thank you guys!
Your myInteger iVar is unused b/c of how the compiler generates iVars and synthesizes getters/setters automatically for properties.
The compiler helps you when you declare properties so you don't need to declare your own iVars or use #synthesize unless you want behavior other than the default.
The line #property(nonatomic) NSInteger myInteger; causes the compiler to generate the equivalent of the following in your implementation.
#synthesize myInteger = _myInteger;
Therefore, the iVar being modified by the default setter is _myInteger.
You can do one of the following in SecondViewController. I prefer solution #1 b/c it is cleaner, less code and takes advantage of automatic compiler behavior.
In SecondViewController.h remove the myInteger iVar and in SecondViewController.m change any references to the iVar to either _myInteger or self.myInteger
or
In SecondViewController.m, explicitly synthesize the property to use your iVar by adding #synthesize myInteger;
EDIT: ADDED SPECIFIC EXAMPLE
// SecondViewController.h
#interface SecondViewContoller : UIViewController
#property(nonatomic) NSInteger myInteger;
#end
// SecondViewControl.m
-(void)viewDidLoad {
NSLog(#" the number is = %d", self.myInteger);
}
// FirstViewController.h
#import "SecondViewController"
//...
// FirstViewController.m
//
// rest of implementation
//
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath) {
NSIndexPath *path = indexPath;
NSInteger theInteger = path.row;
NSLog(#"selected row = %d", theInteger);
SecondViewController *second = [[SecondViewController alloc] init];
second.myInteger = theInteger;
// you need to present second somehow, viewDidLoad won't be called until then
// example if using a navigationController
[self.navigationController pushViewController:second animated:YES];
}
}
Passing parameters onto the next one should be done in the prepareForSegue:sender: method assuming you're using Storyboards in Xcode 4.5.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE"])
{
SecondViewController *second = (SecondViewController *)segue.destinationViewController;
second.selectedIndex = selectedIndex;
}
}
Then in your didSelectRowAtIndexPath: method you can perform the segue:
[self performSegueWithIdentifier:#"YOUR_SEGUE_NAME_HERE"];
And it should pass the parameter to your second view again assuming you have a property in the header file of your SecondViewController like such:
#property (nonatomic, assign) int *selectedIndex;
EDIT:
In context with what you're trying to do you can easily make a private property in your FirstViewController at the top and store your selectedIndex from your didSelectRowAtIndexPath: there and pass it through in the prepareForSegue:
#interface FirstViewController() {
int selectedIndex;
}
And
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndex = indexPath.row
}
Hi i think you are missing to synthesize the myInteger Veriable modify your secondviewcontroller.m file
SecondViewControl.m
#synthesize myInteger;
-(void)viewDidLoad {
NSLog(#" the number is = %d",myInteger);
}
Hopefully this will help you :)

Why is my delegate method not called?

this is probably simple but I'm stuck!
Basically I have a parent and child view controller, and I'm trying to pass data from the child to the parent.
//Child VC interface
#protocol ANSearchGetawayFilterDelegate
-(void)selectedCell:(NSString *)cellTitle;
#end
#interface ANSearchGetawayFilterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
{
NSString* cellTitle;
}
#property (nonatomic, assign) id<ANSearchGetawayFilterDelegate> delegate;
#end
//Child VC implementation
#implementation ANSearchGetawayFilterViewController
#synthesize delegate = _delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellTitle = selectedCell.textLabel.text;
[[self delegate] selectedCell:cellTitle];
[self dismissModalViewControllerAnimated:YES];
}
//Parent VC interface
#import "ANSearchGetawayFilterViewController.h"
#interface ANGetawayFilterViewController : UIViewController <ANSearchGetawayFilterDelegate>
{
NSString* _cellText;
}
//Parent VC Implementation
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
search.delegate = self;
}
return self;
}
//delegate method
-(void)selectedCell:(NSString *)cellTitle
{
_cellText = cellTitle;
NSLog(#"cell text %#", _cellText);
}
the delegate method is never called and when is NSLog the _cellText else where it comes up as null...what am I doing wrong? Thanks!
You are most likely creating a new instance of ANSearchGetawayFilterViewController when you present it and not configuring the delegate on it.
When you called
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
search.delegate = self;
you created an instance of ANSearchGetawayFilterViewController and then set the delegate up correctly, but you never stored this instance of ANSearchGetawayFilterViewController anywhere. So later on when you come to present it you call again
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
which gives you a completely different instance, which you then need to configure again. For example
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
ANSearchGetawayFilterViewController *search1 = [[ANSearchGetawayFilterViewController alloc] init];
NSLog(#"%d", search1 == search);
#=> 0
To fix update your code to be
- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField;
{
BOOL shouldBeginEditing = YES;
NSLog(#"text field should begin editing");
ANSearchGetawayFilterViewController *myANSearchGetawayFilterViewController = [[[ANSearchGetawayFilterViewController alloc] init] autorelease];
myANSearchGetawayFilterViewController.delegate = self; // <--- configure the delegate
[self presentModalViewController:myANSearchGetawayFilterViewController animated:YES];
[self closeAllPickers];
return shouldBeginEditing;
}
I wouldn't make it an ivar as the likelihood is you will present this viewController momentarily just to select some data and then get rid of it, so it is probably safe to discard it and make a new one each time.
Au contraire, the delegate method is being called (hence the NSLog()). However, _cellText is (null) because the value being passed in is nil, ergo selectedCell.textLabel.text.
Firstly, are you sure that the -selectedCell method is being called?
You can do this by putting an NSLog() before or after -tableViewDidSelectRow...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
NSLog(#"TABLEVIEW DID SELECT ROW BEFORE -> %# <-", cellTitle);
[[self delegate] selectedCell:cellTitle];
NSLog(#"TABLEVIEW DID SELECT ROW DELEGATE CALLED");
...
}
Also, you might want to do some cleanup (optional)
Firstly, you are leaking in your initialisation method. Either set the ANGetawayFilterViewController as a property of the parent class using the delegate, or release it after you set the delegate.
Secondly, in the -tableViewDidSelectRow, your code assumes that the delegate has the -selectedCell method coded. If you don't have the method implemented, then the application will result in a crash. You can prevent this by checking to see if the delegate -respondsToSelector...:
if ([self.delegate respondsToSelector:#selector(selectedCell:)]) {
[self.delegate selectedCell:cellTitle];
}
Thirdly, the method of which is being called by the delegate to notify the parentViewController doesn't follow the general schema that delegate methods use, with the exception of -numberOfRowsInSection (UITableViewDelegate). Your method should contain the actual ANFilterGetawayViewController instance too:
- (void) filterGetawayViewController:(ANSearchGetawayFilterViewController *) controller didSelectCellWithTitle:(NSString *) title {
...
}
It can be called as such:
[self.delegate filterGetawayViewController:self didSelectCellWithTitle:cellTitle];
Are you using ARC? Because when the init function ends, your object (and it's reference to the delegate) are cleaned up. What happens if you make the search variable a global one (defining it in your header and initializing it in your code)?
Assuming you are using ARC:
You need to make a retained #property for your ANSearchGetawayFilterViewController instance. It will have been released by ARC by the time the delegate method is called. Do something like this.
#property (strong, nonatomic) ANSearchGetawayFilterViewController *search;
...
#synthesize search = _search;
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
self.search = [[ANSearchGetawayFilterViewController alloc] init];
self.search.delegate = self;
}
return self;
}
Not related to your problem, but best practice is to check if the delegate actually implements the method you expect it to before calling it, like so:
if ([self.delegate respondsToSelector:#selector(selectedCell:)]) {
[self.delegate selectedCell:cellTitle];
}

deleteRowsAtIndexPaths from outside RootViewController class

I am using XCode's Navigation-based Application template to create an app that centers around an UITableView. I am having some problems deleting some rows in the tableView.
In all of the tableViews cells I have added a button by subclassing UITableViewCell like this:
TableViewCell.h:
#implementation TableViewCell
#synthesize button;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
RoutinesAppDelegate *appDelegate = (RoutinesAppDelegate *) [[UIApplication sharedApplication]delegate];
// Initialization code
button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setFrame:CGRectMake(320.0 - 90.0, 6.0, 80.0, 30.0)];
[button setTitle:#"Done" forState:UIControlStateNormal];
[button addTarget:appDelegate action:#selector(routineDone) forControlEvents:UIControlEventTouchUpInside];
button.hidden = YES;
[self.contentView addSubview:button];
}
return self;
}
when the button is pressed the method "routineDone" in RoutinesAppDelegate.m is called.
The method looks like this:
RoutinesAppDelegate.m
-(void) routineDone
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[self todayListPath]])
{
int indexToRemove = buttonIndex + 1;
todayListArray = [NSMutableArray arrayWithContentsOfFile:[self todayListPath]];
[todayListArray removeObjectAtIndex:indexToRemove];
[todayListArray writeToFile:[self todayListPath] atomically:YES];
}
}
This method removes an item from the array that the tableView loads. This works fine.
MY PROBLEM:
The cell is not removed from the screen, when the button is clicked.
In RoutinesAppDelegate.m I tried to use
[tableView reloadData]
but it does not seem to work from outside the RootViewController class.
It would be nice if I somehow could use the deleteRowsAtIndexPaths method, but I dont know how to call that method from outside commitEditingStyle in the RootViewController class.
So my question is really: How can make the cell go away? :)
Without seeing all the code it's hard to tell, but you can try adding after
[todayListArray writeToFile:[self todayListPath] atomically:YES];
[self.tableView reloadData];
Also, you don't have to retain that button, and probably don't have to have it as a property