Reputation: 300
I have a UIButton in the first view. When I click on a button I pushed a 2nd view having table view with data .i want the data of particular row selected by the user in 2nd view sent to the first view.In short second view row data on 1st view while selecting a row on poping to first view?please help .
thanks in advance.
Upvotes: 0
Views: 181
Reputation: 854
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Your First View Controller.index = index path.row
}
Upvotes: 0
Reputation: 7226
Go to your second view, In the method of your UITableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Add the condition if(indexPath.row == 0)
in which you would use a global string already declared in your AppDelegate.m
file to pass data to your previous view using the popViewController
method.
This string will be equal to your cell.textLabel.text
.
Example
if(indexPath.row == 0)
{
textString = cell.textLabel.text;
}
and so on for your various rows. Similarly you can add the textString to your cell of the first table in the 1'st view. Any doubt please tell. Thanks :)
Upvotes: 0
Reputation: 3918
You can use delegate to send data from selected row in 2nd view to the 1st view. I wrote a tutorial on how to use delegates here: http://krodev.wordpress.com/2012/10/08/objective-c-delegates/.
When you setup a delegate, use 2nd view method to send selected row's data back to 1st view:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// row index
int rowIndex = indexPath.row.
// when you have row index you can get row data from your table view datasource
// if your data is NSString (method name depends on your implementation of delegate)
[self.firstViewDelegate selectedRowsData:(NSString *)data];
// return to the 1st view
[self.navigationController popToRootViewControllerAnimated:YES];
}
Upvotes: 2