我有一个带有表视图的视图控制器。我还有一种方法,当选择表视图的单元格之一时,该方法应该推送到新的视图控制器。新的视图控制器包含一个标签,我希望该标签显示所选单元格内容的全文。
目前,当选择单元格时,先前选择的单元格的内容会显示在标签上。这是我的 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