尝试在UITableView中插入行时收到错误

时间:2014-08-13 04:29:16

标签: ios objective-c uitableview

我的功能:

-(void)insertDownloadedActions:(NSMutableArray *)dataToAdd
{


    int64_t delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {

        NSMutableArray *indexPaths = [NSMutableArray array];
        NSInteger currentCount = self.dataSource.count;//getting error :" property 'dataSource' not found on object type xxxViewController"

        for (int i = 0; i < dataToAdd.count; i++) {
            [indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]];
        }


        [self.dataSource addObjects:dataToAdd]; //getting error :" property 'dataSource' not found on object type xxxViewController"


        [tblListResult beginUpdates];
        [tblListResult insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
        [tblListResult endUpdates];
    });
}

我在&lt;&gt;中添加了UITableViewDatasource of .h文件。如何解决? 怎么了 ?谢谢

3 个答案:

答案 0 :(得分:0)

好像你还没有宣布过&#39; dataSource&#39;实例正确。 Xcode表示它无法在&#39; dataSource&#39;的名称中找到任何实例。

self. dataSource替换为dataSource

答案 1 :(得分:0)

您需要从ViewController声明接口中的NSMutableArray并初始化数组(例如在viewDidLoad中)。

@interface ViewController
@property (nonatomic, strong) NSMutableArray *dataSource;
@end


- (void)viewDidLoad
{
     [super viewDidLoad];
     self.dataSource = [NSMutableArray array];
}

答案 2 :(得分:0)

UITableView本身具有称为dataSource的属性。请查看Apple的文档

<强>数据源

充当接收表视图的数据源的对象。

@property(nonatomic,assign)id dataSource

<强>讨论

数据源必须采用UITableViewDataSource协议。不保留数据源。

<强>状况

适用于iOS 2.0及更高版本。 也可以看看   @property delegate

声明

UITableView.h

只需将您自己的 dataSource重命名为其他名称,例如dataList

相关问题