Bogdan
Bogdan

Reputation: 412

Change title of UITableView to a cell name in iOS

I have a UITableView with some rows that are allocated dynamically. When I tap on a row I will go to another TableView using a push Segue, how do I change the second table view title to the cell name of the first table view cell that was tapped?

Upvotes: 5

Views: 3053

Answers (3)

dsplatonov
dsplatonov

Reputation: 773

In swift try

    let selectedCell = self.SomeTableView.cellForRow(at: indexPath) as? SomeTableViewCell
    if let cell = selectedCell {
        // get text from cell label for example
    }

Upvotes: 0

Bogdan
Bogdan

Reputation: 412

I made a string where i stored the cell title in tabeViewDidSelectRowAtIndexPath and I passed it in the prepareForSegue but the title string but when I tapped on the cell the first method to be called was prepareForSegue and the string would get instantiated after that so i called

[self performSegueWithIdentifier: @"nameOfSegue" sender: self];

in tabeViewDidSelectRowAtIndexPath and it worked.

Upvotes: 0

Ratikanta Patra
Ratikanta Patra

Reputation: 1177

Just use the following code inside tableViewDidSelectRowAtIndexPath method

UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
NSString *title=cell.textLabel.text;

Now you can pass the string title to the next table view.

Upvotes: 3

Related Questions