navigationController+tableview时,tableView的textlabel不能自动延长,而且tableview进入编辑状态后,不显示“+”号圆圈或减号圆圈
代码如下:
这个是UITableViewController的代码:
#import "CZShowNumberTableViewController.h"
#import "CZContact.h"
#import "CZContactCell.h"
//#import "CZAddPeopleViewController.h"
//#import "CZFoundPeopleViewController.h"
#define CZContactPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"contact.data"]
@interface CZShowNumberTableViewController ()//
@property(nonatomic,strong)NSMutableArray *contacts;
@implementation CZShowNumberTableViewController
//懒加载
-(NSMutableArray *)contacts{
if (_contacts==nil) {
_contacts=[NSKeyedUnarchiver unarchiveObjectWithFile:CZContactPath] ;
if (_contacts==nil) {
_contacts=[NSMutableArray array];
}
}
return _contacts;
}
//编辑按钮
(IBAction)cencelClick:(UIBarButtonItem *)sender {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"亲,确定要注销吗?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[self presentViewController:alert animated:YES completion:^{
}];
UIAlertAction *sure=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];
UIAlertAction *cencle=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:sure];
[alert addAction:cencle];
}
(void)viewDidLoad {
[super viewDidLoad];
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
UIBarButtonItem *rightItem=self.navigationItem.rightBarButtonItem;
UIBarButtonItem *editItem=[[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(editClick:)];
self.navigationItem.rightBarButtonItems=@[rightItem,editItem];
}
#pragma mark - TableView DataSource
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;//self.contacts.count;
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"contacts"];
// CZContactCell *cell=[CZContactCell contactCell:tableView];
// cell.contact=self.contacts[indexPath.row];
cell.textLabel.text=@"234567890-=";
cell.detailTextLabel.text=@"34567890-=";
return cell;
}
#pragma mark - TableView Delegate
//设置编辑模式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.tableView.isEditing) {
return UITableViewCellEditingStyleInsert;
}else{
return UITableViewCellEditingStyleDelete;
}
}
//2、设置编辑执行的操作
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.contacts removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
[NSKeyedArchiver archiveRootObject:self.contacts toFile:CZContactPath];
}else if (editingStyle == UITableViewCellEditingStyleInsert) {
CZContact *newContact=[[CZContact alloc]init];
newContact.name=@"rose";
newContact.phoneNum=@"12345678910";
[self.contacts insertObject:newContact atIndex:indexPath.row+1];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];
[NSKeyedArchiver archiveRootObject:self.contacts toFile:CZContactPath];
}
}
ps:tableviewCell是rightDetil模式