I want to convert NSIndexPath
to NSString
. How would I do it?
I have to use this:
- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)sourcePath
{
[client deletePath:@"/objc/boston_copy.jpg"];
}
inside commitEditingStyle method where I only get NSIndexPath
as input.
- (void)tableView:(UITableView *)aTableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath :(NSIndexPath *)indexPath
{
[self.itemArray removeObjectAtIndex:indexPath.row];
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:YES];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:UITableViewRowAnimationFade];
}
I made this a category on NSIndexPath at one point in time:
@interface NSIndexPath (StringForCollection)
-(NSString *)stringForCollection;
@end
@implementation NSIndexPath (StringForCollection)
-(NSString *)stringForCollection
{
return [NSString stringWithFormat:@"%d-%d",self.section,self.row];
}
@end
I made this extension to help with debugging:
@interface NSIndexPath (DBExtensions)
- (NSString *)indexPathString;
@end
@implementation NSIndexPath (DBExtensions)
- (NSString *)indexPathString;
{
NSMutableString *indexString = [NSMutableString stringWithFormat:@"%lu",[self indexAtPosition:0]];
for (int i = 1; i < [self length]; i++){
[indexString appendString:[NSString stringWithFormat:@".%lu", [self indexAtPosition:i]]];
}
return indexString;
}
@end
You can't convert an NSIndexPath to a string -- an NSIndexPath is effectively just an array of integers. Assuming by "convert" you mean that you want to access the data associated with a particular path, you have to go back to the source of that data.
If you generated the table from an array of objects, which is commonly the case, then you'll simply look at the object at the array index equal to the first element of the indexPath. If the table is sectioned then you need to look at how the data was accessed in order to create the sections -- it likely relates to sorting of the objects based on some object property.
There's no conversion, there's just looking at the data source the same way it was accessed when generating the table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With