Quote:
Originally Posted by thehindutimes
In this method, I guess NSMutableArray order will consist of Ints describing the indexPath, right?
But how do I get the string object from the array the indexPath is pointing to?
- (void)tableView  UITableView *)tableView didSelectRowAtIndexPath  NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if([order containsObject:indexPath]){
[order removeObject:indexPath];
} else {
[order addObject:indexPath];
}
[tableView reloadData];
}
Thanks!
|
Your code above doesn't make any sense. You would be well served by opening XCode, going to the help system, and reading the documentation on the classes you are trying to use. The documentation is generally quite good, and very informative. In this case, it's clear that you have no idea what an NSIndexPath is or how to use it.
Table views are divided into sections and rows. When the user selects a cell, you need 2 numbers to describe the cell, a section number and a row number.
The NSIndexPath object is a specialized object that will save a whole series of values. Table views use index path objects to specify a section and row.
In a method like didSelectRowAtIndexPath that receives an index path, you can get the section and row like this:
Code:
int row = indexPath.row;
int section = indexPath.section;
If your table view doesn't use sections, you can just ignore the section.
The index path does not point to anything. It gives you the row and section number, and you can use those values to index into the array of data that describes your table.
If the data is an array tableArray that contains strings, you could use code like this:
Code:
int row = indexPath.row;
NSString* selectedEntryString = [tableArray objectAtIndex: row];
You are creating lots of posts where you post some code that is a complete mess, and ask the forum why it doesn't work. It's pretty clear from your posts that you're just slapping stuff together without knowing anything about the fundamentals of Objective C or Cocoa Touch.
Why don't you do yourself (and us) a favor and buy yourself a tutorial book on iPhone programming and go work through the exercises?