也许我没有问正确的称号,对不起这个,我是一个初学者,所以我会解释一下:如何创建一个从表视图返回编辑模式的segue?
我有2个屏幕: 1.创建笔记 - 这个屏幕有一个视图控制器,TextView和导航(创建/取消)。 2.注释页面 - 此屏幕有一个表格视图控制器和一个带有加号按钮的导航。 (非常类似于苹果笔记应用程序)
我想的是,在表视图,每当我单击单元格,将带我回到这个笔记的编辑页面...
所以我加推从单元格延伸到笔记页面,每次我点击一个单元格时,它都会打开一个新的笔记页... 所以我知道我在这里错过了一些东西,如果你能帮我弄清楚它会很感激
这是我的表视图控制器.m文件:
#import "NMNotesListViewController.h"
#import "NMCreateNotesViewController.h"
@interface NMNotesListViewController()
@property (strong, nonatomic) NSMutableArray *notes;
@end
@implementation NMNotesListViewController
- (IBAction) unwindToList: (UIStoryboardSegue *) segue
{
NMCreateNotesViewController *source = [segue sourceViewController];
NMNote *note = source.note;
if (note != nil) {
[self.notes addObject:note];
[self.tableView reloadData];
}
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.notes = [[NSMutableArray alloc] init];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.notes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NotesPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NMNote *note = [self.notes objectAtIndex:indexPath.row];
cell.textLabel.text = note.content;
return cell;
}
@end
这是我的视图控制器(创建笔记).m文件:
#import "NMCreateNotesViewController.h"
@interface NMCreateNotesViewController()
@property (weak, nonatomic) IBOutlet UIBarButtonItem *createButton;
@property (weak, nonatomic) IBOutlet UITextView *textField;
@end
@implementation NMCreateNotesViewController
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect bkgndRect = self.textField.superview.frame;
bkgndRect.size.height += kbSize.height;
[self.textField.superview setFrame:bkgndRect];
[self.textField setContentOffset:CGPointMake(0.0, self.textField.frame.origin.y-kbSize.height) animated:YES];
}
- (void) keyboardWillBeHidden: (NSNotification *) aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.textField.contentInset = contentInsets;
self.textField.scrollIndicatorInsets = contentInsets;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.createButton) return;
if (self.textField.text.length > 0) {
self.note = [[NMNote alloc] init];
self.note.content = self.textField.text;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
请随时提出新的标题,这个问题可以帮助别人 – Joe
首先,你不“推背” - 一个推的是一个特定的术语,意思添加新的控制器上的导航堆栈导航控制器(即前往新控制器)并显示新控制器。当你回去时,你会弹出,而不是推。如果您使用的是导航控制器,则应该点击“后退”按钮返回。另一种返回的方式是将数据传回给前一个控制器的方法是取消放弃。 – rdelmar