I have the following code which fetches a string from an array of strings and split开发者_如何学JAVAs the string into 2 parts.
NSString *temp = [tableViewData objectAtIndex:indexPath.row];
NSArray *tempArray = [temp componentsSeparatedByString: @"_"];
cell.textLabel.text = [tempArray objectAtIndex:1];
and the String which is added is as follows
newTitle = [NSString stringWithFormat:@"%d_%@",[Daily_QuoteViewController counter],title];
[plistArray addObject:newTitle];
[plistArray writeToFile:filepath atomically: YES];
Which is adding an index and a string.
I am trying to then split that string in the first code section. but trying to access the second part of the string at index 1 gives an out of bounds error.
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
What is the best way to split the string in order to use both parts of the string
split firstPart_secondPart
Thanks in advance.
This seems fine to me. Can you print out NSString temp? NSLog(@"%@", temp);
精彩评论