views:

251

answers:

1

If i have to show 10 or 30 or 100 strings in a uitableview..How to get the selected raw from that.. My value for each row is different .I mean i have to set the row value and display name from a 2 dimenional NSArray.. Somebody please help me..

+1  A: 

I would setup an NSMutableArray of the objects your table rows represent. You can use your own class or NSDictionaries, one per row. My data source implementation (UITableViewDataSource protocol) of -tableView:cellForRowAtIndexPath: would set each cell's content (be it strings, images or anything else) to the appropriate object of the NSMutableArray. My delegate implementation (UITableViewDelegate protocol) of -tableView: didSelectRowAtIndexPath: would be called whenever a row is selected and the supplied NSIndexPath would point to the corresponding object's index in the NSMutableArray.

Basically, just implement UITableViewController which is by default both the data source and the delegate of the table view, put the objects you need to "show" in the table into an NSMutableArray and implement -tableView:numberOfRowsInSection:, -tableView:cellForRowAtIndexPath: and -tableView: didSelectRowAtIndexPath: in the most straight-forward manner. The first method returns the number of rows per section, the second configures a cell for each row, the third is sent when a row is selected.

Costique