When I select a UITableViewCell, my view controller label is the action beyond

I have a view controller with a table view. I also have a method that should click on the new view controller if one of the table cells is selected. The new view controller contains the label, and I would like the label to display the full text of the contents of the selected cell.

Currently, previously selected cell content is displayed on the label when the cell is selected. Here is the current contents of my ViewController.m file (delegate and data source are declared in the header file)

    #import "ViewController.h"



    @interface ViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *tweetsArray;

@end

@implementation ViewController

- (void)viewDidLoad
{
    self.tableView.dataSource = self;

    self.tableView.delegate = self;

    self.tweetsArray = [[NSArray alloc] initWithObjects:
                   @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus",
                   @"eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Cu",
                   @" Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero v",
                   @" eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales",
                   nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tweetsArray.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"SettingsCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    NSString *tweet = [self.tweetsArray objectAtIndex:indexPath.row];

    [cell.textLabel setText:tweet];
    [cell.detailTextLabel setText: @"Cody be Cray"];

    return cell;
}

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier: @"DetailViewController"];
    dvc.tweet = [self.tweetsArray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:dvc animated:YES];
}

@end
+4
source share
1 answer

"didDeselect", "didSelect" tableview.

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
}

, :

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
}
+8

Source: https://habr.com/ru/post/1541057/


All Articles