当我选择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.
目前,先前选择的单元格的内容是选择单元格时标签上显示。以下是我的ViewController.m文件的当前内容(委托和数据源在头文件中声明)
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)
#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
推荐答案
你有一个didDeselect而不是didSelecttableview委托方法。
You have a "didDeselect" rather than "didSelect" tableview delegate method there.
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
}
应该是这样的:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
}
这篇关于当我选择UITableViewCell时,我的视图控制器标签就是后面的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!