我有一个UITableViewController,当用户点击上一个ViewController中的一行(显示该应用的所有联系人)时,就会调用该控件。
我正在研究的这个观点需要显示详细信息。 现在我只与
合作最终我会添加更多信息,但这是我想要使用的概念证据数据。
传递到此场景的信息是从 Person 对象填充的。
我正在试图找出当用户点击编辑时我可以做些什么。
我只需要一些帮助或推动正确的方向。
以下是我对此ViewController的代码
//
// SingleContactViewController.h
// General view to display a single person record
#import <UIKit/UIKit.h>
#import "PublicContactsViewController.h"
#import "Person.h"
@interface SingleContactViewController : UITableViewController <ADBannerViewDelegate>
@property (nonatomic, strong) Person *person;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *editButton;
@property (nonatomic, assign, getter=isPrivate) BOOL private;
@property (strong, nonatomic) IBOutlet UITextField *firstNameTextField;
@property (strong, nonatomic) IBOutlet UITextField *lastNameTextField;
@property (strong, nonatomic) IBOutlet UITextField *homeEmailTextField;
@property (strong, nonatomic) IBOutlet UITextField *workEmailTextField;
@end
//
// SingleContactViewController.m
//
#import "SingleContactViewController.h"
#import "Person.h"
@interface SingleContactViewController ()
@property (strong, nonatomic) IBOutlet ADBannerView *banner;
@property (nonatomic, assign) BOOL isEditing;
- (IBAction)popBackToContacts:(UIBarButtonItem *)sender;
- (IBAction)editContact:(UIBarButtonItem *)sender;
@end
@implementation SingleContactViewController
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.498 green:0 blue:.0 alpha:1];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_banner.delegate = self;
NSLog(@"SingleContactView - viewDidLoad method: person = %@",self.person.firstName);
self.firstNameTextField.text = [self.person.firstName copy];
self.lastNameTextField.text = [self.person.lastName copy];
self.homeEmailTextField.text = [self.person.homeEmail copy];
self.workEmailTextField.text = [self.person.workEmail copy];
}
#pragma mark - Editing Methods
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
NSLog(@"Entered setEditing");
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
if (editing == YES){
// Change views to edit mode.
}
else {
//
}
}
- (IBAction)editContact:(UIBarButtonItem *)sender {
NSLog(@"User pressed 'Edit' button. Entered editContact method");
if ([self.tableView isEditing]) {
// If the tableView is already in edit mode, turn it off. Also change the title of the button to reflect the intended verb (‘Edit’, in this case).
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonSystemItemDone target:self action:@selector(editContact:)];
self.navigationItem.rightBarButtonItem = newButton;
_editButton = newButton;
[self.tableView setEditing:NO animated:YES];
}
else {
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonSystemItemEdit target:self action:@selector(editContact:)];
self.navigationItem.rightBarButtonItem = newButton;
_editButton = newButton;
[self.tableView setEditing:YES animated:YES];
}
}
#pragma mark - Navigation Methods
- (IBAction)popBackToContacts:(UIBarButtonItem *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Perform Delete
// Animate the deletion
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade];
}
}
@end
答案 0 :(得分:1)
我没有查看你的代码。根据你问的帮助我问的问题:
使用表格视图显示用户联系详细信息。 (这是我看到的)
当用户点击“编辑”时,将用户带到新的视图控制器(没有动画和隐藏导航栏),以便用户不理解页面的更改。
向用户显示联系人的所有属性(如果先前已填充或未填充),获取值并显示它们以进行编辑。当点击“完成编辑”时,将他引回用户详细信息视图 - 控制器(无动画)并更新表视图(值存在或不存在的属性是否为空,这解决了第二个问题)。因此,用户不会了解单独的编辑页面,但您的目的已经解决
现在出现了第三个问题,
答案 1 :(得分:0)
我发现了这个StaticDataTableViewControlller,它立即解决了我的问题。 我很欣赏这篇文章中的帮助!