質問

私は、しかし、私は唯一の代わりに、セルごとのファイル、すべての細胞内のディレクトリの最後のファイルを取得しています、テーブルビューで着メロ・ディレクトリの内容を一覧表示しようとしています。これは私のコードです:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    Profile_ManagerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.hidesAccessoryWhenEditing = YES;
    }

    cell.accessoryType = UITableViewCellAccessoryNone;
    //cell.textLabel.text = @"No Ringtones";
    //cell.textLabel.text = @"Test";

    NSString *theFiles;
    NSFileManager *manager = [NSFileManager defaultManager];
    NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
    for (NSString *s in fileList){
        theFiles = s;
    }
    cell.textLabel.text = theFiles;

    return cell;
}

これは、エラー、細かいロードしない私はNSLogを使用する場合には、ディレクトリ内のすべてのファイルがうまく示しています。私も[s objectAtIndex:indexPath.row]を試してみましたが、私はをobjectAtIndex取得:のエラーを。誰もが任意のアイデアがありますか?

役に立ちましたか?

解決

あなたのforループは、ファイルだけを反復処理し、現在のパスにtheFilesを設定しています。だから、ループの最後で、theFilesはちょうどコレクション内の最後の文字列になります。

のようなものを試してみてください。

cell.textLabel.text = [fileList objectAtIndex:indexPath.row];

他のヒント

私は実際に、ここに質問をして、10分未満で原因を愛し、私は自分の質問に答える!

これは私が動作するように上記のコードを得た方法である。

NSMutableArray *theFiles;
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
for (NSString *s in fileList){
    theFiles = fileList;
}
cell.textLabel.text = [theFiles objectAtIndex:indexPath.row];
return cell;

私はNSMutableArrayのNSStringのを作って、それは私がobjectAtIndexを使用することができました。今、ファイルの拡張子をトリミングする!

あなたはNSStringの、NSMutableArrayのループのために削除する必要があります。..最終的なコードは次のようにする必要があります:

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
cell.textLabel.text = [fileList objectAtIndex:indexPath.row];
return cell;

ところで、こののfileListとマネージャーは...各セルごとに繰り返し作成されたので、それのUITableViewControllerのグローバル変数にし、わずか1

を割り当てる方が良いです
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top