Print all items in NSMutablearray
ios, nsmutablearray, uitextview
Solution
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
[selectItems addObject:[stands objectAtIndex:indexPath.row]];
NSMutableString *exString = [[NSMutableString alloc]init];
for (NSString *yourVar in selectItems) {
NSLog (@"Your Array elements are = %@", yourVar);
[exString appendFormat:@"\n%@",yourVar];
}
selectedItems.text=exString;
[self.mytableView reloadData];
}
What about something like this? It takes each object, puts a newline in it, then adds it to exString to form one long chain of the objects in your array.
Problem
My program has a tableview, I want to show selected items from the tableview in a textview I have following code which shows only the last item of the NSMutablearray in textview: I guess problem is the for loop but couldnt figure it out. stands is NSMutablearray, selectItems is NSMutablearray, selected items is UItexview. ``` - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { [selectItems addObject:[stands objectAtIndex:indexPath.row]]; for (NSString *yourVar in selectItems) { selectedItems.text=yourVar; NSLog (@"Your Array elements are = %@", yourVar); } [self.mytableView reloadData]; } ``` I try the following but it crashes: ``` [selectItems addObject:[stands objectAtIndex:indexPath.row]]; int length = [selectItems count]; for(int i=0;i<=length;i++){ selectedItems.text= [selectItems objectAtIndex:i]; } ``` how can I show all the items of NSmutablearray in a texview ?