iphone - UItableView删除行使用函数

标签 iphone objective-c ios

我有 NSMutableArray“day”,其中包含(6 个 NSMutable 数组)数组包含

class Lesson{
    NSString *time1;
    NSString *time2;
    NSString *predmet;
    NSString *namPrepod;
    NSString *zamet;
}

我有获取当前周、日、课的功能

-(Lesson *)lessonInWeek:(int)week inDay:(int)day lessonNumber:(int)lNumber
{
    Week *currentWeek = nil;
    if(week)    
        currentWeek = nechetNedel;
    else        
        currentWeek = chetNedel;

    NSMutableArray *dayArray = [currentWeek.days objectAtIndex:day];
    Lesson *lesson = [dayArray objectAtIndex:lNumber];

    return lesson;
}

用这个函数我展示在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
......
 Lesson *item = [[Singleton sharedInstance] lessonInWeek:segmentedControl.selectedSegmentIndex inDay:indexPath.section lessonNumber:indexPath.row];

    ....
    time1.text= item.time1;
    ....

    time2.text= item.time2;
    ....
    predmet.text=item.predmet;
    .....
    namePrepod.text=item.namPrepod;
    ......
    zamet.text=item.zamet;
    ....

谁可以在不使用 的情况下使用此功能删除行?

if(segmentedControl.selectedSegmentIndex==0)
if(section==1)
......

删除一行需要编辑的函数。

最佳答案

deleteLessonInWeek:inDay:lessonNumber: 添加到您的单例类中,并从您的 tableView:commitEditingStyle:forRowAtIndexPath: 实现中调用它:

- (void) tableView:(UITableView*)tableView
    commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
    forRowAtIndexPath:(NSIndexPath*)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [[Singleton sharedInstance] deleteLessonInWeek:segmentedControl.selectedSegmentIndex inDay:indexPath.section lessonNumber:indexPath.row];
    }
}

Singleton 中的实现可以使用查找日期数组的相同简洁模式,然后是一天中的类(class),然后删除请求的项目:

-(void)deleteLessonInWeek:(int)week inDay:(int)day lessonNumber:(int)lNumber {
    // Choose odd or even week:
    Week *currentWeek = week ? nechetNedel : chetNedel;
    NSMutableArray *dayArray = [currentWeek.days objectAtIndex:day];
    [dayArray removeObjectAtIndex:lNumber];
}

关于iphone - UItableView删除行使用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9141506/

相关文章:

ios - ios10 safari 的 html 页面中的视频元素是否有限制

iphone - 创建 plist 文件 iOS 不工作

iphone - 如何从我自己的应用程序打开 iphone 邮件应用程序?

ios - Swift:自定义 UIView 未根据约束调整大小

ios - 如何在导航栏中创建后退按钮

ios - 跨多个 UITableViewCells 拆分单个核心数据对象

ios - Flutter IOS应用程序不会以image_picker开头:^ 0.6.3 + 4

iphone - 如何使用UIViewContentModeAspectFit将图像添加到UIButton?

android - 媒体查询仅被某些手机匹配

objective-c - iPhone : Unable to understand the following coding