2016-11-01 24 views
0

私は国名を持つテーブルビューを持っています。セルをタップすると、そのセルを国に関するテキストとともに詳細ビューに移動します。セル内のタイトルと同じ名前の各国の別のtxtファイル(例:USA.txt)があります。詳細ビューに(正しい)txt-fileを入力してください

これらのtxtファイルを詳細表示で表示するにはどうすればよいですか?

私のコードは、これまでに次のようになります。

TableViewController.h

@property (nonatomic, strong) NSArray *Title; 

TableViewController.m

- (void)viewDidLoad { 
[super viewDidLoad]; 

_Title = @[@”Afganistan”, 
     @”Albania”, 
     @”Algeria”, 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"TableCell"; 
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

int row = [indexPath row]; 

cell.TitleLabel.text = _Title[row]; 

return cell; 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

if ([[segue identifier] isEqualToString:@"ShowDetails"]) { 
    DetailViewController *detailviewcontroller = [segue destinationViewController]; 

    NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 

    int row = [myIndexPath row]; 
    detailviewcontroller.DetailModal = @[_Title[row]]; 
    } 
} 

DetailViewController.h

@property (strong, nonatomic) IBOutlet UILabel *TitleLabel; 

@property (strong, nonatomic) NSArray *DetailModal; 

DetailViewContro ller.m

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

_TitleLabel.text = _DetailModal[0]; 

self.navigationItem.title = _DetailModal[0]; 

} 

私は以下のコードをStackOverflowで見つけましたが、実装方法はわかりません。あなたが必要とする

NSString *path = [[NSBundle mainBundle]pathForResource:@”Afganistan” ofType:@"txt"]; 
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 

答えて

1

.txtファイルの内容を表示する(detailLabelを言う)UILabel 1以上を取ることができます。 DetailViewControllerののviewDidLoadでは、それは素晴らしい仕事を、ライン

NSString *path = [[NSBundle mainBundle]pathForResource:_DetailModal[0] ofType:@"txt"]; 
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 
self.detailLabel.text = content 
self.detailLabel.numberOflines = 0 
+0

ありがとうござい下に追加 ! :) –

+0

乾杯.. upvoteを忘れないでください..ありがとう –

関連する問題