0

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
4

5 に答える 5

1

選択したセル オブジェクトを取得しています。そのオブジェクトを TextView に渡すだけで、選択したセル データが動的に読み込まれます。注意すべき重要なことは、最初にビュー コントローラーをプッシュしてから、そのコントローラーにデータを渡すことです。コードでは、最初にデータを渡しました。次に、View Controllerをプッシュしましたが、機能しません

于 2013-05-18T05:11:38.113 に答える
0
- (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];
    }
    **myUiTextView.text =[yourarray  indexPath.row];
}

このコードに従ってください。このコードが役立つ場合があります。

于 2013-05-18T04:21:56.413 に答える