Ios 网间网操作系统。表视图单元格滑动努力工作

Ios 网间网操作系统。表视图单元格滑动努力工作,ios,objective-c,uitableview,swipe,Ios,Objective C,Uitableview,Swipe,我有自定义的表格视图单元格。此代码用于刷卡删除: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return reportingCellIndexPath != indexPath; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ NSInteger r

我有自定义的表格视图单元格。此代码用于刷卡删除:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return reportingCellIndexPath != indexPath;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSInteger result = [self.messagesModel numberOfDifferentDayDatesInMessages];
    return result;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSDate *sectionDate = [self.messagesModel dayDateAtNumber:section];
    NSInteger rowsCount = [self.messagesModel numberOfMessagesWithDayDate:sectionDate];
    return rowsCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger realMessageIndex = [self.messagesModel fullMessageIndexForMessageWithDayDateNumber:indexPath.section index:indexPath.row];


    SDMessage *message = [self.messagesModel messageAtIndex:realMessageIndex];
//    SDMessage *message = [self.messagesModel messageAtIndex:indexPath.row withDayDateAtNumber:indexPath.section];
    static NSString *messageCellId = @"messageCellId";
    SDMessageCell *_messageCell = [tableView dequeueReusableCellWithIdentifier:messageCellId];
    if (_messageCell == nil) {
        _messageCell = [[SDMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:messageCellId];
    }
    [_messageCell rebuildWithMessage:message];
    _messageCell.delegate = self;
    if ([reportingCellIndexPath isEqual:indexPath] &&
        ![_messageCell reportViewIsShowing]) {
        [_messageCell showReportViewWithMessagesModel:self.messagesModel messageIndex:realMessageIndex];
    } else if ([_messageCell reportViewIsShowing]) {
        [_messageCell hideReportView];
    }
    return _messageCell;


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat result = [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
    return result;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSDate *sectionDate = [self.messagesModel dayDateAtNumber:section];
    if (sectionDate != nil) {
        return [self sectionTitleForSectionDate:sectionDate];
    } else {
        return @"";
    }
}


- (NSString *)sectionTitleForSectionDate:(NSDate *)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterShortStyle];
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDate *now = [NSDate date];

    NSDateComponents *dateComponents = [calendar components:
                                        NSYearCalendarUnit |
                                        NSMonthCalendarUnit |
                                        NSDayCalendarUnit |
                                        NSWeekdayCalendarUnit |
                                        NSWeekCalendarUnit
                                                   fromDate:date];
    NSDateComponents *nowComponents = [calendar components:NSYearCalendarUnit |
                                       NSMonthCalendarUnit |
                                       NSDayCalendarUnit |
                                       NSWeekdayCalendarUnit |
                                       NSWeekCalendarUnit
                                                  fromDate:now];

    if (dateComponents.year == nowComponents.year &&
        dateComponents.month == nowComponents.month &&
        dateComponents.week == nowComponents.week) {
        if (nowComponents.weekday - dateComponents.weekday < 2) {
            [dateFormatter setDoesRelativeDateFormatting:YES];
        } else {
            [dateFormatter setDateFormat:@"EEEE"];
        }
    }

    return [dateFormatter stringFromDate:date];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self cancelSearchField];
    NSInteger realMessageIndex = [self.messagesModel fullMessageIndexForMessageWithDayDateNumber:indexPath.section index:indexPath.row];
    if (indexPath.row < self.messagesModel.size && realMessageIndex > -1) {

        [self.messagesModel selectMessageAtIndex:realMessageIndex];

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
            self.refreshBeforeShowing = NO;
            [self.navigationController pushViewController:self.detailViewController animated:YES];
        }
    }
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSInteger realMessageIndex = [self.messagesModel fullMessageIndexForMessageWithDayDateNumber:indexPath.section index:indexPath.row];
        [SDModalLoadingIndicator showLoading];
        [self.messagesModel deleteMessageAtIndex:realMessageIndex success:^() {
            [SDModalLoadingIndicator hideLoading];

            NSString *msg = NSLocalizedString(@"Message has been deleted", nil);
            [[[[iToast makeText:msg]
               setDuration:iToastDurationNormal]
              setGravity:iToastGravityBottom] show];
            [self.tableView reloadData];
        } failureCallback:^(NSString *message, NSMutableArray *validationErrors, NSError *error) {
            [SDModalLoadingIndicator hideLoading];
            [SDFailureHandler handleConnectFailure:message withError:error];
        }];
    }
}
-(BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(nsindepath*)indepath{
return reportingCellIndexPath!=indepath;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
NSInteger result=[self.messages不同日期消息的模型编号];
返回结果;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
NSDate*sectionDate=[self.messagesModelDaydateAtNumber:section];
NSInteger rowsCount=[self.messagesModel numberOfMessagesWithDayDate:sectionDate];
返回Rowsunt;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
NSInteger realMessageIndex=[self.messages模型fullMessageIndexForMessageWithDayDateNumber:indepath.section index:indepath.row];
SDMessage*message=[self.messagesModel messageAtIndex:realMessageIndex];
//SDMessage*message=[self.messagesModel messageAtIndex:indexPath.row withDayDateAtNumber:indexPath.section];
静态NSString*messageCellId=@“messageCellId”;
SDMessageCell*_messageCell=[tableView dequeueReusableCellWithIdentifier:messageCellId];
如果(_messageCell==nil){
_messageCell=[[SDMessageCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:messageCellId];
}
[_messagecellrebuildwithmessage:message];
_messageCell.delegate=self;
if([reportingCellIndexPath isEqual:indexPath]&&
![\u messageCell reportViewIsShowing]){
[\u messageCell showReportViewWithMessagesModel:self.messagesModel messageIndex:realMessageIndex];
}else if([\u messageCell reportViewIsShowing]){
[_messagecellhidereportview];
}
返回消息单元;
}
-(CGFloat)tableView:(UITableView*)表视图行高度索引路径:(NSIndexPath*)索引路径{
CGFloat结果=[self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
返回结果;
}
-(CGFloat)表格视图:(UITableView*)表格视图头部高度部分:(NSInteger)部分{
返回40;
}
-(NSString*)表格视图:(UITableView*)表格视图标题标题标题部分:(NSInteger)部分{
NSDate*sectionDate=[self.messagesModelDaydateAtNumber:section];
如果(节日期!=零){
返回[自分段标题截止日期:分段日期];
}否则{
返回@”;
}
}
-(NSString*)区段标题区段日期:(NSDate*)日期{
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];
[日期格式化程序setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSCalendar*日历=[NSCalendar currentCalendar];
NSDate*现在=[NSDate日期];
NSDateComponents*dateComponents=[日历组件:
国家统计局日历股|
NSMonthCalendarUnit|
国家统计局日历单位|
NSWeekdayCalendarUnit|
NSWeekCalendarUnit
fromDate:日期];
NSDateComponents*nowComponents=[日历组件:NSYearCalendarUnit|
NSMonthCalendarUnit|
国家统计局日历单位|
NSWeekdayCalendarUnit|
NSWeekCalendarUnit
起始日期:现在];
如果(dateComponents.year==nowComponents.year&&
dateComponents.month==nowComponents.month&&
dateComponents.week==nowComponents.week){
if(nowComponents.weekday-dateComponents.weekday<2){
[dateFormatter setDoesRelativeDateFormatting:是];
}否则{
[日期格式化程序setDateFormat:@“EEEE”];
}
}
返回[dateFormatter stringFromDate:date];
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{
[自我取消搜索字段];
NSInteger realMessageIndex=[self.messages模型fullMessageIndexForMessageWithDayDateNumber:indepath.section index:indepath.row];
if(indexath.row-1){
[self.messages模型selectMessageAtIndex:realMessageIndex];
如果(用户界面习惯用法()==UIUserInterfaceIdiomPhone){
self.refreshBeforeShow=否;
[self.navigationController pushViewController:self.detailViewController动画:是];
}
}
}
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径{
如果(editingStyle==UITableViewCellEditingStyleDelete){
NSInteger realMessageIndex=[self.messages模型fullMessageIndexForMessageWithDayDateNumber:indepath.section index:indepath.row];
[SDModalLoadingIndicator showLoading];
[self.messages模型deleteMessageAtIndex:realMessageIndex成功:^(){
[SDModalLoadingIndicator hideLoading];
NSString*msg=NSLocalizedString(@“消息已被删除”,无);
[[iToast makeText:msg]
设置持续时间:iToastDurationNormal]
setGravity:iToastGravityBottom]show];
[self.tableView重载数据];
}failureCallback:^(NSString*消息,NSMutableArray*验证错误,NSError*错误){
[SDModalLoadingIndicator hideLoading];
[SDFailureHandler HandleConnectionFailure:消息错误:错误];
}];
}
}
但几乎总是在刷卡时不显示删除按钮(有时会显示删除按钮)。有人知道为什么吗

我试着调试这个东西,通过调试器检查所有视图,它们只有系统手势识别器(平移、轻触、长按、边缘)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle != UITableViewCellEditingStyleDelete)
        return;

    // perform the delete!
}