Here is my problem:
By pushing a button on the DetailViewController I want to receive the data of my next row.
Here is what I tried so far:
-(IBAction)next:(id)sender {
question.text = [questions objectAtIndex:indexPath.row+1];
}
But now it takes the data that is stored in row 1. But I want to retrieve the data from the next row in line.
question
is the name of my label I want the text to be displayed in.
questions
is the name of my NSMutableArray o store my data in.
Here is the complete Code:
//
// NINDetailViewController.m
// NIN
//
// Created by Hegg Roger on 27.06.13.
// Copyright (c) 2013 Hegg. All rights reserved.
//
#import "NINDetailViewController.h"
#import "NIN.h"
@interface NINDetailViewController ()
@end
@implementation NINDetailViewController
@synthesize transfer;
@synthesize content;
@synthesize questions;
@synthesize questions1;
@synthesize answers;
@synthesize question;
@synthesize questionTableView;
@synthesize indexPath;
/*
-(IBAction)next:(id)sender {
question.text = [questions objectAtIndex:indexPath.row+1];
}
-(IBAction)prev:(id)sender {
}
*/
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
questions = [[NSMutableArray alloc]initWithObjects:
@"1. Wie lautet die richtige Reihenfolge beim Arbeiten an elektrischen
Installationen (Arbeitssicherheit)?",
@"2. Was versteht man unter dem Begriff UVG?",
@"3. Was ist die wichtigste Bestimmung des UVGs?",nil];
questions1 = [[NSMutableArray alloc]initWithObjects:
@"1. Was bedeuten die Abkürzungen NIV / NIN / StV?",nil];
[super viewDidLoad];
content.text = transfer;
// question.text = [questions objectAtIndex:indexPath.row];
}
- (NSInteger)tableView : (UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [questions count];
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *simpleTableIdentifier = @"questionCell";
UITableViewCell *cell = [questionTableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
if ([content.text isEqualToString:@"Unfallverhütung"]) {
question.text = [questions objectAtIndex:indexPath.row];
}
else
if ([content.text isEqualToString:@"Grundlagen / Begriffe / Kennzeichnungen"]) {
question.text = [questions1 objectAtIndex:indexPath.row];
}
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@TBlue: I got this Error with your suggestion: