IOS - 表格视图未加载

发布于 2025-01-04 05:24:28 字数 2018 浏览 1 评论 0原文

嘿,我是 iOS 开发新手,在我的应用程序中,我想将视频文件从文档文件夹获取到表视图。但文件没有在表视图中加载。所以请告诉我我在哪里犯了错误..

- (void)viewDidLoad
{

    [super viewDidLoad];
    tblView.delegate = self;
    NSFileManager *filemgr = [NSFileManager defaultManager];
    NSString *docDirPath = NSHomeDirectory();
    docDirPath = [docDirPath stringByAppendingPathComponent:@"Documents"];
    NSArray *filelist = [filemgr contentsOfDirectoryAtPath:docDirPath error:NULL];
    NSLog(@"filelist = %@",filelist);
    int count = [filelist count];
    NSString *currentFileName;
    videoListNames = [NSMutableArray array];
    for (int j = 0; j<count; j++) 
    {
        currentFileName = (NSString *)[filelist objectAtIndex:j];
        if ([[currentFileName pathExtension] isEqualToString:@".avi"]) 
        {
            NSLog(@"currentFileName = %@",currentFileName);
            [videoListNames addObject:currentFileName];
        }
    }
    [tblView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return videoListNames.count;
}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    //TRY TO REMOVE ALL CONTENT
    for(UIView *view in cell.contentView.subviews){
        if ([view isKindOfClass:[UIView class]]) {
            [view removeFromSuperview];
        }
    }

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //cell.backgroundView.frame = 
    cell.textLabel.text = (NSString *)[videoListNames objectAtIndex:indexPath.row];
    NSLog(@"cell text = %@",cell.textLabel.text);
    // Configure the cell.
    return cell;

}

Hey i am new to iOS development, in my app i want to fetch video file from document folder to table view. But the files are not getting load in table view. so please tell me where am i making a mistake..

- (void)viewDidLoad
{

    [super viewDidLoad];
    tblView.delegate = self;
    NSFileManager *filemgr = [NSFileManager defaultManager];
    NSString *docDirPath = NSHomeDirectory();
    docDirPath = [docDirPath stringByAppendingPathComponent:@"Documents"];
    NSArray *filelist = [filemgr contentsOfDirectoryAtPath:docDirPath error:NULL];
    NSLog(@"filelist = %@",filelist);
    int count = [filelist count];
    NSString *currentFileName;
    videoListNames = [NSMutableArray array];
    for (int j = 0; j<count; j++) 
    {
        currentFileName = (NSString *)[filelist objectAtIndex:j];
        if ([[currentFileName pathExtension] isEqualToString:@".avi"]) 
        {
            NSLog(@"currentFileName = %@",currentFileName);
            [videoListNames addObject:currentFileName];
        }
    }
    [tblView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return videoListNames.count;
}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    //TRY TO REMOVE ALL CONTENT
    for(UIView *view in cell.contentView.subviews){
        if ([view isKindOfClass:[UIView class]]) {
            [view removeFromSuperview];
        }
    }

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //cell.backgroundView.frame = 
    cell.textLabel.text = (NSString *)[videoListNames objectAtIndex:indexPath.row];
    NSLog(@"cell text = %@",cell.textLabel.text);
    // Configure the cell.
    return cell;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所的.畏惧 2025-01-11 05:24:28

你是否忘记设置:

tblView.datasource = self;

have you forgotten to set:

tblView.datasource = self;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文