IOS - 表格视图未加载
嘿,我是 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是否忘记设置:
have you forgotten to set: