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 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?