Queen_Easy 2015-11-21 07:06
浏览 1542

Object-c 问题,tableViewController问题

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;

  • (IBAction)cencelClick:(UIBarButtonItem *)sender; @end

@implementation CZShowNumberTableViewController

//懒加载
-(NSMutableArray *)contacts{
if (_contacts==nil) {
_contacts=[NSKeyedUnarchiver unarchiveObjectWithFile:CZContactPath] ;
if (_contacts==nil) {
_contacts=[NSMutableArray array];
}
}
return _contacts;
}
//编辑按钮

  • (void)editClick:(UIBarButtonItem *)editItem{ [self.tableView setEditing:!self.tableView.editing animated:YES]; //[self.tableView]; // [self.tableView layoutIfNeeded]; editItem.title=self.tableView.isEditing?@"完成":@"编辑"; } //注销按钮
  • (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模式

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学的三元一次方程求解
    • ¥20 iqoo11 如何下载安装工程模式
    • ¥15 本题的答案是不是有问题
    • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
    • ¥15 C++使用Gunplot
    • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题