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];
ありがとうござい下に追加 ! :) –
乾杯.. upvoteを忘れないでください..ありがとう –