سؤال

I need to create a NSString for browsing folders in FTP share. i show the directory on a TableView, and user´s can browse by selecting row ´s

Im writing the string of selected rows into a mutable array, and then i need to make a string of all strings in the mutable array. means add the last string to the previous when the row is selected

for example first string in array is "Downloads" second "Movies" third "HD-Movies"....... and so on for that i need the string on the first time selected row "/Downloads/" the second time "/Downloads/Movies/", an the third "/Downloads/Movies/HD-Movies"

i´m sure i need a NSMutableString, but don´t know how to add the strings...

here a part of my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

NSMutableArray *filePathArray = [[NSMutableArray alloc]init];
[filePathArray addObject:@"/Downloads/"];
[filePathArray addObject:[fileNameArray objectAtIndex:indexPath.row]];

}
هل كانت مفيدة؟

المحلول

You can do like this:

NSString *string=[array componentsJoinedByString:@"/"];

This will give you :

Downloads/Movies/HD-Movies

Now if you want / in front than you can simply append an /.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top