我有一个 UITableView 和另一个视图。另一个视图有一个 UITextView,我希望根据选择的表视图中的哪一行来填充不同的文本。如果我为所有不同的文本选项创建不同的视图,我知道该怎么做。如果我这样做,我可以在点击该行时打开该视图。我只是想避免创建一堆不同的视图,而只使用一个加载不同文本的视图,具体取决于在表格视图中点击的行。我想我只需要知道带有文本视图的视图如何从表视图访问 indexPath.row 。有什么建议么?
编辑:这是我的代码。
LHRRoster.m
#import "LHRRoster.h"
#import "CustomCellBackground.h"
#import "OnMyHonor.h"
#import "AVA.h"
#import "Receivers.h"
#import "BandDetailView.h"
@interface LHRRoster ()
@end
@implementation LHRRoster
{
NSMutableArray *mbTableData;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
mbTableData = [NSMutableArray arrayWithObjects:@"Aesthetics Versus Architecture", @"On My Honor", @"Receivers", @"Skyscraper Stereo", @"California", @"Late Ones", @"Uh-Huh Baby Yeah", @"Danielle Bouchard", @"Chris Karrer", @"Joey Blue", @"The Codas", @"Your Favorite Hero", @"Nixon", @"Skam Impaired", @" SaySomethingHugeOnFire", @"Adore Me Not", @"Common Collective", @"The Royal Tees", @"The Gravetones", @"Bush League", @"Rock & Roll Television", @" Tastyface", @"The Lips", @"Mercy Academy", @"Audiostrobelight", nil];
self.title = @"LHR Roster";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mbTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *mbTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mbTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mbTableIdentifier];
cell.textLabel.font=[UIFont systemFontOfSize:14.0];
}
cell.backgroundView = [[CustomCellBackground alloc] init];
cell.selectedBackgroundView = [[CustomCellBackground alloc] init];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
cell.textLabel.text = [mbTableData objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BandDetailView *detailView = [[BandDetailView alloc]initWithNibName:@"BandDetailView" bundle:nil];
if (indexPath.row == 0)
{
detailView.title = @"Aesthetics vs Architecture";
UIImage *image = [UIImage imageNamed: @"AVA.png"];
[detailView.bandPic setImage:image];
NSString *bio = @"";
[detailView.bandInfo setText:bio];
[self.navigationController pushViewController:detailView animated:YES];
}
}
@end