I'm trying to make an iOS application where the user opens the app, and simply taps on a cell to view information on a certain topic. I have everything set up accordingly I think, however when I run the app and tap on a cell, my .txt file is not showing up in the textView. What am I doing wrong?
.m file of detail view controller
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize detailText = _detailText;
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated{
self.textView.text = _detailText;
}
.h file of detail view controller
@interface DetailViewController : UIViewController
@property (nonatomic, retain) UITextView *detailText;
@property (strong, nonatomic) IBOutlet UITextView *textView;
@end
*.m file of tableviewcontroller*
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.tableViewText = [[UITextView alloc] init];
[super viewDidLoad];
self.titleObjectsArray = @[@"D 1.1",
@"D 1.2",
@"D 1.3",
@"D 1.4",];
self.subtitleObjectsArray = @[@"Pharmaceutical Products",
@"Pharmaceutical Products",
@"Pharmaceutical Products",
@"Pharmaceutical Products",];
self.textObjectsArray = @[@"D 1.1.txt",
@"D 1.2.txt",
@"D 1.3.txt",
@"D 1.4.txt",];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.titleObjectsArray count];;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.titleObjectsArray objectAtIndex: indexPath.row];
cell.detailTextLabel.text = [self.subtitleObjectsArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.tableViewText.text = [self.textObjectsArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"detail" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"detail"]) {
DetailViewController *detailVC = (DetailViewController *)segue.destinationViewController;
detailVC.detailText = self.tableViewText;
}
}