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