I have created a small table view(no scroll) and want the user to select an option. To know which option was selected I defined an int type in header file of the view controller and exposed it as a property.I defined the method:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//some code here/
int optionSelected = indexPath.row;
}
Now I want to use this int optionSelected in other view controller but it doesn’t work. Besides it gives an error in the function I defined above saying “Unused variable ‘optionSelected'”. Please tell me where can I possibly be going wrong. Thank you.
You’re redeclaring
optionSelectedas a local variable in the code above. This means you aren’t assigning it to your instance variable, so any attempt to use it later on won’t work. Remove theintfrom the start of the line. This will remove the warning and, if everything else is OK, give you access to the selected row index elsewhere in your class.