【问题标题】:Label doesn't show text标签不显示文字
【发布时间】:2014-08-15 23:33:15
【问题描述】:

当我启动我的应用程序时,点击我的 RootViewController (AufnahmeIstTableViewController) 中的一个单元格,它会打开我的 DetailViewController (AufnahmeISTDetailTableViewController)。然后当我点击单元格时,它应该会打开第三个 ViewController (AufnahmeIstDetailDetailViewController )。我的应用程序像本教程中一样工作:http://www.youtube.com/watch?v=99Ssk1-HUq4

但是当我点击一个单元格并打开我的第三个视图时,我的第三个视图控制器上的标签不会显示代码中声明的任何文本。

我需要改变什么?这是我所有的文件:

这是我的 AufnahmeIstTableViewController.h 文件:

#import <UIKit/UIKit.h>

@interface AufnahmeIstTableViewController : UITableViewController

@property (strong, nonatomic) NSMutableArray *categoryArray;
@end

这是我的 AufnahmeIstTableViewController.m 文件:

#import "AufnahmeIstTableViewController.h"
#import "AufnahmeISTDetailTableViewController.h"

@interface AufnahmeIstTableViewController ()

@end

@implementation AufnahmeIstTableViewController
@synthesize categoryArray;


-(NSMutableArray *)categoryArray
{
    if (!categoryArray)

    {
        categoryArray = [[NSMutableArray alloc]init];
    }
    return categoryArray;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.categoryArray addObject:@"Gesetze"];
    [self.categoryArray addObject:@"Verordnungen"];
    [self.categoryArray addObject:@"Technische Regeln"];
    [self.categoryArray addObject:@"Berufsgenossenschaft"];
    [self.categoryArray addObject:@"Management"];
    [self.categoryArray addObject:@"Personal"];
    [self.categoryArray addObject:@"Vertrieb"];
    [self.categoryArray addObject:@"Kunden"];
    [self.categoryArray addObject:@"Lieferanten"];
    [self.categoryArray addObject:@"Arbeitsumgebung"];
    [self.categoryArray addObject:@"Produktion"];
    [self.categoryArray addObject:@"Produkte"];
    [self.categoryArray addObject:@"Messmittel"];
    [self.categoryArray addObject:@"Informationssicherheit"];
    [self.categoryArray addObject:@"Rechnungswesen"];
    [self.categoryArray addObject:@"Dritte"];

    [self setTitle:@"Ist-Aufnahme"];


    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.categoryArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.textLabel.text = self.categoryArray [indexPath.row];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AufnahmeISTDetailTableViewController *categories = [[AufnahmeISTDetailTableViewController alloc]init];

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Gesetze"])
        categories.istAufnahmeInt = 0;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Verordnungen"])
        categories.istAufnahmeInt = 1;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Technische Regeln"])
        categories.istAufnahmeInt = 2;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Berufsgenossenschaft"])
        categories.istAufnahmeInt = 3;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Management"])
        categories.istAufnahmeInt = 4;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Personal"])
        categories.istAufnahmeInt = 5;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Vertrieb"])
        categories.istAufnahmeInt = 6;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Kunden"])
        categories.istAufnahmeInt = 7;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Lieferanten"])
        categories.istAufnahmeInt = 8;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Arbeitsumgebung"])
        categories.istAufnahmeInt = 9;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Produktion"])
        categories.istAufnahmeInt = 10;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Produkte"])
        categories.istAufnahmeInt = 11;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Messmittel"])
        categories.istAufnahmeInt = 12;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Informationssicherheit"])
        categories.istAufnahmeInt = 13;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Rechnungswesen"])
        categories.istAufnahmeInt = 14;

    if ([[self.categoryArray objectAtIndex:indexPath.row] isEqual:@"Dritte"])
        categories.istAufnahmeInt = 15;


    [categories setTitle:[self.categoryArray objectAtIndex:indexPath.row]];
        //[self.navigationController pushViewController:categories animated:YES];
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - Navigation
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"DetailView"])
{
    AufnahmeISTDetailTableViewController *controller = (AufnahmeISTDetailTableViewController *)segue.destinationViewController;
    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Gesetze"])
        controller.istAufnahmeInt = 0;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Verordnungen"])
        controller.istAufnahmeInt = 1;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Technische Regeln"])
        controller.istAufnahmeInt = 2;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Berufsgenossenschaft"])
        controller.istAufnahmeInt = 3;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Management"])
        controller.istAufnahmeInt = 4;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Personal"])
        controller.istAufnahmeInt = 5;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Vertrieb"])
        controller.istAufnahmeInt = 6;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Kunden"])
        controller.istAufnahmeInt = 7;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Lieferanten"])
        controller.istAufnahmeInt = 8;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Arbeitsumgebung"])
        controller.istAufnahmeInt = 9;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Produktion"])
        controller.istAufnahmeInt = 10;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Produkte"])
        controller.istAufnahmeInt = 11;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Messmittel"])
        controller.istAufnahmeInt = 12;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Informationssicherheit"])
        controller.istAufnahmeInt = 13;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Rechnungswesen"])
        controller.istAufnahmeInt = 14;

    if ([[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row] isEqual:@"Dritte"])
        controller.istAufnahmeInt = 15;

    [controller setTitle:[self.categoryArray objectAtIndex:[self.tableView indexPathForSelectedRow].row]];
}
}


@end

这是我的 AufnahmeISTDetailTableViewController.h 文件:

#import <UIKit/UIKit.h>
#import "AufnahmeIstTableViewController.h"
#import "AufnahmeIstDetailDetailViewController.h"

@interface AufnahmeISTDetailTableViewController : UITableViewController {
    NSMutableArray *gesetzeArray;
    NSMutableArray *verordnungenArray;
    NSMutableArray *technischeregelnArray;
    NSMutableArray *berufsgenossenschaftArray;
    NSMutableArray *managementArray;
    NSMutableArray *personalArray;
    NSMutableArray *vertriebArray;
    NSMutableArray *kundenArray;
    NSMutableArray *lieferantenArray;
    NSMutableArray *arbeitsumgebungArray;
    NSMutableArray *produktionArray;
    NSMutableArray *produkteArray;
    NSMutableArray *messmittelArray;
    NSMutableArray *informationssicherheitArray;
    NSMutableArray *rechnungswesenArray;
    NSMutableArray *dritteArray;


}
@property int istAufnahmeInt;
@property AufnahmeIstTableViewController *categories;

-(void)makeData;


@end

这是我的 AufnahmeISTDetailTableViewController.m 文件:

#import "AufnahmeISTDetailTableViewController.h"
#import "AufnahmeIstTableViewController.h"
#import "AufnahmeIstDetailDetailViewController.h"

@interface AufnahmeISTDetailTableViewController ()

@end

@implementation AufnahmeISTDetailTableViewController
@synthesize istAufnahmeInt;
@synthesize categories;


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];

        // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self makeData];

}
-(void)makeData
{
    gesetzeArray = [[NSMutableArray alloc]init];
    verordnungenArray = [[NSMutableArray alloc]init];
    technischeregelnArray = [[NSMutableArray alloc]init];
    berufsgenossenschaftArray= [[NSMutableArray alloc]init];
    managementArray= [[NSMutableArray alloc]init];
    personalArray= [[NSMutableArray alloc]init];
    vertriebArray= [[NSMutableArray alloc]init];
    kundenArray= [[NSMutableArray alloc]init];
    lieferantenArray= [[NSMutableArray alloc]init];
    arbeitsumgebungArray= [[NSMutableArray alloc]init];
    produktionArray= [[NSMutableArray alloc]init];
    produkteArray= [[NSMutableArray alloc]init];
    messmittelArray= [[NSMutableArray alloc]init];
    informationssicherheitArray= [[NSMutableArray alloc]init];
    rechnungswesenArray= [[NSMutableArray alloc]init];
    dritteArray= [[NSMutableArray alloc]init];

    //Gesetze
        [gesetzeArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];

    //Verordnungen
        [verordnungenArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Verordnung zur arbeitsmedizinischen Vorsorge – ArbMedVV",@"name",@"Verordnung zur arbeitsmedizinischen Vorsorge – ArbMedVV wurde gedrückt",@"description", nil]];

    //Technische Regeln
        [technischeregelnArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Technische Regeln",@"name",@"Technische Regeln wurde gedrückt", @"description", nil]];
    //Berufsgenossenschaft
        [berufsgenossenschaftArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Berufsgenossenschaft",@"name",@"Berufsgenossenschaft wurde gedrückt", @"description", nil]];
    //Management
        [managementArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Personal
        [personalArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Vertrieb
        [vertriebArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Kunden
        [kundenArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Lieferanten
        [lieferantenArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Arbeitsumgebung
        [arbeitsumgebungArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Produktion
        [produktionArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Produkte
        [produkteArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Messmittel
        [messmittelArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Informationssicherheit
        [informationssicherheitArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Rechnungswesen
        [rechnungswesenArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
    //Dritte
        [dritteArray addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Bundesdatenschutzgesetz",@"name",@"Bundesdatenschutzgesetz wurde gedrückt", @"description", nil]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    if (self.istAufnahmeInt == 0)
    {
        return [gesetzeArray count];
    }
    if (self.istAufnahmeInt == 1)
    {
        return [verordnungenArray count];
    }
    if (self.istAufnahmeInt == 2)
    {
        return [technischeregelnArray count];
    }
    if (self.istAufnahmeInt == 3)
    {
        return [berufsgenossenschaftArray count];
    }
    if (self.istAufnahmeInt == 4)
    {
        return [managementArray count];
    }
    if (self.istAufnahmeInt == 5)
    {
        return [personalArray count];
    }
    if (self.istAufnahmeInt == 6)
    {
        return [vertriebArray count];
    }
    if (self.istAufnahmeInt == 7)
    {
        return [kundenArray count];
    }
    if (self.istAufnahmeInt == 8)
    {
        return [lieferantenArray count];
    }
    if (self.istAufnahmeInt == 9)
    {
        return [arbeitsumgebungArray count];
    }
    if (self.istAufnahmeInt == 10)
    {
        return [produktionArray count];
    }
    if (self.istAufnahmeInt == 11)
    {
        return [produkteArray count];
    }
    if (self.istAufnahmeInt == 12)
    {
        return [messmittelArray count];
    }
    if (self.istAufnahmeInt == 13)
    {
        return [informationssicherheitArray count];
    }
    if (self.istAufnahmeInt == 14)
    {
        return [rechnungswesenArray count];
    }
    if (self.istAufnahmeInt == 15)
    {
        return [dritteArray count];
    }
    else
    {
        return 1;
    }
    [self.tableView reloadData];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier1 = @"DetailCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1 forIndexPath:indexPath];
    if (cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
    }

    // Configure the cell...
                if (self.istAufnahmeInt == 0) cell.textLabel.text = [[gesetzeArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 1) cell.textLabel.text = [[verordnungenArray objectAtIndex:indexPath.row]objectForKey:@"name" ];
                if (self.istAufnahmeInt == 2) cell.textLabel.text = [[technischeregelnArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 3) cell.textLabel.text = [[berufsgenossenschaftArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 4) cell.textLabel.text = [[managementArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 5) cell.textLabel.text = [[personalArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 6) cell.textLabel.text = [[vertriebArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 7) cell.textLabel.text = [[kundenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 8) cell.textLabel.text = [[lieferantenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 9) cell.textLabel.text = [[arbeitsumgebungArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 10) cell.textLabel.text = [[produktionArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 11) cell.textLabel.text = [[produkteArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 12) cell.textLabel.text = [[messmittelArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 13) cell.textLabel.text = [[informationssicherheitArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 14) cell.textLabel.text = [[rechnungswesenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
                if (self.istAufnahmeInt == 15) cell.textLabel.text = [[dritteArray objectAtIndex:indexPath.row]objectForKey:@"name"];


    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AufnahmeIstDetailDetailViewController *aufnahmeistDetail =[[AufnahmeIstDetailDetailViewController alloc]initWithNibName:@"AufnahmeIstDetailDetailViewController"  bundle:nil];

    if (istAufnahmeInt == 0)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[gesetzeArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[gesetzeArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 1)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[verordnungenArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[verordnungenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 2)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[technischeregelnArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[technischeregelnArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 3)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[berufsgenossenschaftArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[berufsgenossenschaftArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 4)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[managementArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[managementArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 5)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[personalArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[personalArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 6)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[vertriebArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[vertriebArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 7)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[kundenArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[kundenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 8)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[lieferantenArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[lieferantenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 9)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[arbeitsumgebungArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[arbeitsumgebungArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 10)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[produktionArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[produktionArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 11)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[produkteArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[produkteArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 12)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[messmittelArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[messmittelArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 13)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[informationssicherheitArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[informationssicherheitArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 14)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[rechnungswesenArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[rechnungswesenArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }

    if (istAufnahmeInt == 15)
    {
        aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[dritteArray objectAtIndex:indexPath.row]objectForKey:@"name"]];
        aufnahmeistDetail.title = [[dritteArray objectAtIndex:indexPath.row]objectForKey:@"name"];
    }


}
@end

这是我的 AufnahmeISTDetailTableViewController.h 文件:

#import <UIKit/UIKit.h>
#import "AufnahmeISTDetailTableViewController.h"
@interface AufnahmeIstDetailDetailViewController : UIViewController

{
    IBOutlet UILabel *titleLabel;
    IBOutlet UILabel *textLabel;
    NSString *titelString;
    NSString *textString;
}
@property (nonatomic, retain) NSString *titelString;
@property (nonatomic, retain) NSString *textString;


@end

最后,这是我的 AufnahmeISTDetailTableViewController.m 文件:

#import "AufnahmeIstDetailDetailViewController.h"
#import "AufnahmeISTDetailTableViewController.h"

@interface AufnahmeIstDetailDetailViewController ()

@end

@implementation AufnahmeIstDetailDetailViewController
@synthesize textString;
@synthesize titelString;

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Do any additional setup after loading the view.
    titleLabel.text = titelString;
    textLabel.text = textString;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

【问题讨论】:

    标签: ios objective-c xcode uitableview uilabel


    【解决方案1】:

    我的建议是设置断点并确保设置标签的代码实际上设置了正确的字符串值。如果您确定这一点,那么您的 IB 文件一定有问题(可能是 clearColor 文本?)。

    另一方面,您的视图控制器中有大量的硬编码。您应该将数据与视图分离。

    【讨论】:

      【解决方案2】:

      考虑到 Messmittel 和 Lieferanten 阵列,这听起来像是一个内部应用程序或用于 OBI 的应用程序,但这超出了范围,除此之外。

      tilo 的建议是正确的,如果您想通过情节提要获得控制器并在将对象传递给它的同时继续使用它。

      这是我在你的代码中注意到的,从一开始AufnahmeIstTableViewController.h:

      在您的didSelectRowAtIndexPath 中,您实际上不需要根据字符串检查值,因为您的数组实际上包含这些元素,即“Gesetze”、“Verordnungen”、“Technische Regeln”、“Berufsgenossenschaft”等。

      所以基本上你可以这样做:

      controller.istAufnahmeInt = [[self.tableView indexPathForSelectedRow] row];
      

      或者更安全:

      if([self.categoriesArray count] >= [[self.tableView indexPathForSelectedRow] row])
      {
          controller.istAufnahmeInt = [[self.tableView indexPathForSelectedRow] row];
      }
      

      现在在您的prepareForSegue:

      你基本上在那里做同样的事情。所以你真正需要做的只是:

      controller.istAufnahmeInt = categories.istAufnahmeInt;
      

      因此,使用till 的建议将第二个视图控制器的相同逻辑应用于第三个视图控制器,以将字符串传递给它。

      希望这会有所帮助。

      【讨论】:

      • 你能把我需要的代码发给我吗,因为我不知道在他做三个点的地方放什么? @Unheilig
      【解决方案3】:

      在您的第二个视图控制器中,您在实际上并未显示的视图控制器上设置了titelString 和textString。

      你需要在你的第二个视图控制器中实现prepareForSegue:sender::

      - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
      {
          AufnahmeIstDetailDetailViewController *aufnahmeistDetail = [segue destinationViewController];
          int selectedRow  = [self.tableView indexPathForSelectedRow].row;
      
          aufnahmeistDetail.titleString = ...; // get the appropriate string based on the selected row
          aufnahmeistDetail.textString = ...;
      }
      

      【讨论】:

      • 那么你把...放在这里应该是什么样子?
      • 像您在tableView:didSelectRowAtIndexPath: 方法中所做的那样获取适当的字符串(然后可以将其删除)
      • 那么,对吗?这只是一个例子@tilo - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { AufnahmeIstDetailDetailViewController *aufnahmeistDetail = [segue destinationViewController]; int selectedRow = [self.tableView indexPathForSelectedRow].row; if (istAufnahmeInt == 0) { aufnahmeistDetail.titelString = [[NSString alloc]initWithString:[[gesetzeArray objectAtIndex:selectedRow]objectForKey:@"name"]]; aufnahmeistDetail.title = [[gesetzeArray objectAtIndex:selectedRow]objectForKey:@"name"]; } }
      • 这样你会得到你在原始代码中所做的事情。但是,您不使用行索引,即无论您选择哪一行,都会得到相同的结果。
      • 那么你能给我发一个它应该是什么样子的例子吗? @tilo
      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 2018-02-28
      相关资源
      最近更新 更多