In my app there is a table view. When a row in the table view is selected a UIView appears and shows information.
The row title comes from a plist file with strings in it.
The plist file also includes strings with a phone number associated with the row title.
In the custom UIView I have a button, when you click the button I want it to call the number which is declared in the plist file.
The number which is associated with the row the user clicked.
How could I accomplish this?
The action is a ordinary IBAction:
- (IBAction)callNumber:(id)sender;
It is connected to the button in IB (in Xcode 4).
I would appreciate if someone had a solution to my problem, thanks.
Edit
For some clarity, I would like to get the phone number which is associated with the row you select in the table view. The string in the plist has a key, for the phone number name: “phone”.
NSString *phone = [[tableList objectAtIndex:indexPath.row] objectForKey:@"phone"];
“tablelist” is a NSMutableArray. I would like to get the key “phone” and store it in the NSString *phone. All this in a IBAction. Would it help to post the whole class?
You need to have a property on the “custom view” that indicates the index path of the row that was selected. You can put this in your custom view controller’s header to declare this property:
Then, setup the implementation like this:
Now, in the
tableView:didSelectRowAtIndexPath:method, simply create the view controller as usual, but set theindexPathproperty on it so that it can be accessed in the future:Then, anywhere in
MyCustomViewController.m, simply writeself.indexPath.rowto get the row of the index path that was selected.