質問

https://www.dropbox.com/s/duosl4d1fdsxehq/Storyboard.png

Here is my actual storyboard. I am using UINavigation Controller for my app. When I press add, I open the view to add a new expense to my table. The thing is I don't know what I should do when I press on "Save"? I tried to put a new push segue to the previous view and it's working but after the backbutton item propose me to return to the "add new expense" view and it shouldn't do this. How can I just reproduce the animation back button but with my save button?

役に立ちましたか?

解決 2

I know it was a long time ago but you should create a delegate on the second view.

@protocol ExpenseProtocol;

@interface NewExpenseViewController : UIViewController
@property (nonatomic, weak) id<ExpenseProtocol> *delegate;
@end

@protocol ExpenseProtocol <NSObject>
- (void)didCreateNewExpense:(Expense)newExpense;
@end

@implementation NewExpenseViewController

- (void)savePressed:(id)sender {
    if (self.delegate && [self.delegate responseToSelector:@selector(didCreateNewExpense:)]) {
        [self.delegate didCreateNewExpense:_newExpense];
    }
}

@end

Then in your first view controller

@interface ListExpenseViewController () <ExpenseProtocol>
@end

@implementation ListExpenseViewController    

- (void)didCreateNewExpense:(Expense)newExpense {
    if (newExpense) {
        [_arrayExpense addObject:newExpense];
    }
    [self.tableView reloadData];
}

@end

他のヒント

On the second view controller, in the method that handles the click of the save button, add: [self.navigationController popViewControllerAnimated:YES];

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top