いろいろ調べたのですが、どうしても分からないようです。私は iOS 開発にかなり慣れていないので、完全に間違っていることをお詫びします。
これが状況です。
ボタンを使用して DetailViewController のコンテンツ ビューを切り替えようとしています。これにより、次のテキスト ビューまたは同じビューに移動しますが、テキストが異なります。
これは私のヘッダーファイルです。
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextView *rowContent;
@property int rowNumber;
@property (strong, nonatomic) NSString * rowName;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *rightArrow;
@end
私の tableViewController は、選択したセルに応じて、私の DetailViewContoller にリダイレクトします。DetailViewController には、tableViewController に戻って別のセルを選択する代わりに、次のテキストに切り替える別のボタンがあります。
//DetailViewController
//set the title of the view
self.title = rowName;
//set the UITextView basec on rowNumber
switch (rowNumber) {
case 0:
rowContent.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"file" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
break;
case 1:
rowContent.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"file1" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
break;
case 2:
rowContent.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"file2" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
break;
case 3:
rowContent.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"file3" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
break;
default:
break;
//TableViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//create and instance of our DetailViewController
DetailViewController * DVC = [[DetailViewController alloc]init];
//set the DVC to the destinationViewContoller
DVC = [segue destinationViewController];
//get the indexPath
NSIndexPath * path = [self.tableView indexPathForSelectedRow];
NSString * theList = [rowList objectAtIndex:path.row];
DVC.rowNumber = path.row;
DVC.rowName = theList;
}