【发布时间】:2013-06-28 19:42:59
【问题描述】:
这是我的问题:
通过按下 DetailViewController 上的按钮,我想接收下一行的数据。
这是我目前尝试过的:
-(IBAction)next:(id)sender {
question.text = [questions objectAtIndex:indexPath.row+1];
}
但现在它需要存储在第 1 行中的数据。但我想从下一行检索数据。
question是我希望在其中显示文本的标签的名称。questions是我的 NSMutableArray 的名称,用于存储我的数据。
这是完整的代码:
//
// 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:您的建议出现了这个错误:
【问题讨论】:
标签: objective-c row tableview nsindexpath