简体   繁体   English

当我选择UITableViewCell时,我的视图控制器标签就是后面的动作

[英]When I select a UITableViewCell, my view controller label is an action behind

I have a view controller set up with a table view. 我有一个视图控制器设置与表视图。 I also have a method that should push to a new view controller when one of the table view's cells is selected. 我还有一个方法,当选择一个表视图的单元格时,该方法应该推送到新的视图控制器。 The new view controller contains a label, and I would like the label to display the full text of the content of the selected cell. 新的视图控制器包含一个标签,我希望标签显示所选单元格内容的全文。

Currently, the previously selected cell's content is shown on the label when a cell is selected. 目前,当选择单元格时,标签上显示先前选择的单元格内容。 Here is the current content of my ViewController.m file (Delegate and data source are declared in the header file) 这是我的ViewController.m文件的当前内容(委托和数据源在头文件中声明)

    #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

You have a "didDeselect" rather than "didSelect" tableview delegate method there. 你有一个“didDeselect”而不是“didSelect”tableview委托方法。

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

Should probably be this: 应该是这样的:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我点击UITableViewCell时,未推送视图控制器。 - View controller is not pushed when I tap on UITableViewCell. 单击下一个视图控制器的按钮时,如何显示加载标签? - How can I get my loading label to show up when I click button to next view controller? 选择表格视图单元格时无法推送视图控制器 - Can't push my view controller when I select a table view cell 对UITableViewCell内的UITableView行进行操作以打开另一个视图控制器 - Action to UITableView row inside UITableViewCell to open another view controller 如果视图控制器不可滚动,我可以执行“拉动刷新”操作吗? - can I make 'pull to refresh' action if my view controller is not scrollable? 推送视图控制器时标签不显示 - Label not showing up when I push view controller 当用户点击表视图中的行时,如何更新UITableViewCell(原型单元格)中的标签? - How do I update a label in a UITableViewCell (prototype cell) when the user taps the row in the table view? 关闭视图控制器时,在 UITableViewCell 中保存 UICollectionView 的选定状态 - Save selected state of UICollectionView inside UITableViewCell when dismiss the view controller 单击CollectionViewCell INSIDE a UITableViewCell时如何显示视图控制器 - How to show view controller when clicking on CollectionViewCell INSIDE a UITableViewCell 我在我的视图 Controller 中尝试了这种方法,但我真的很喜欢 Label - I tried this as a method in my View Controller, but I'd really like it in a Label
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM