Label doesn't show text - ios

When I launch my app, tap on a cell in my RootViewController (AufnahmeIstTableViewController), it opens up my DetailViewController (AufnahmeISTDetailTableViewController).When I then tap on cell, it should open a third ViewController (AufnahmeIstDetailDetailViewController). My app works like in this tutorial: http://www.youtube.com/watch?v=99Ssk1-HUq4
But when I tap on a cell and open my third view, the labels on my third view controller don't display any text as declared in the code.
What do I have to change? Here are all my files:
Here is my AufnahmeIstTableViewController.h file:
#import <UIKit/UIKit.h>
#interface AufnahmeIstTableViewController : UITableViewController
#property (strong, nonatomic) NSMutableArray *categoryArray;
#end
Here's my AufnahmeIstTableViewController.m file:
#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
Here's my AufnahmeISTDetailTableViewController.h file:
#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
And here's my AufnahmeISTDetailTableViewController.m file:
#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
Here's my AufnahmeISTDetailTableViewController.h file:
#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
And finally, here's my AufnahmeISTDetailTableViewController.m file:
#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

My suggestion is to just set breakpoints and ensure that your code that sets the labels is actually setting the correct string values. If you are sure about that, then there must be something wrong with your IB files (clearColor text, maybe?).
On another note, you have a horrendous amount of hardcoding in your view controllers. You should decouple your data from your views.

It sounds like it is either an in-house App or one for OBI given the Messmittel and Lieferanten arrays, but this is out of the scope and with that aside.
tilo's suggestion is correct, if you would like to get a hold of the controller through storyboard and segue to it while passing objects to it too.
Here is what I have noticed in your code, right from the very first AufnahmeIstTableViewController.h:
In your didSelectRowAtIndexPath you don't actually need to check the values against a string, because your array does in fact contains those elements namely "Gesetze", "Verordnungen", "Technische Regeln", "Berufsgenossenschaft" etc.
So basically you could just to:
controller.istAufnahmeInt = [[self.tableView indexPathForSelectedRow] row];
Or safer:
if([self.categoriesArray count] >= [[self.tableView indexPathForSelectedRow] row])
{
controller.istAufnahmeInt = [[self.tableView indexPathForSelectedRow] row];
}
Now in your prepareForSegue:
You're basically doing the same thing there. So what you really need to do is just:
controller.istAufnahmeInt = categories.istAufnahmeInt;
So apply the same logic for your second view controller to your third using till's suggestion to pass the strings to it.
Hope this helps.

in your second view controller, you are setting titelString and textString on a viewController that you don't actually show.
You need to implement prepareForSegue:sender: in your second view controller:
- (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 = ...;
}

Related

Slide out menu with categories crashes by saying "NSCFString objectAtIndex" while using APExpandableTableView

I am using a third party library to show drop down cells for a slide out menu with an arrow to open the subcategories. Using APExpandableTableView I get an error which says:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7f8612e834f0".
I don't know what I'm doing wrong.
- (void)viewDidLoad {
[super viewDidLoad];
self.expandableTableView.expandableTableViewDelegate = self;
[self customSetup];
// 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)customSetup
{
newArray = [[NSMutableArray alloc] init];
NSString *apiURL = [NSString stringWithFormat:#"%#/products/categories",mainURL];
OAuth1Legged *OAuth = [[OAuth1Legged alloc] init];
NSString *finalURL = [OAuth generateGetURL:apiURL];
[OAuth getJsonResponse:finalURL success:^(NSDictionary *responseDict)
{
dispatch_async( dispatch_get_main_queue(), ^{
self.dataModelArray = [[NSMutableArray alloc] init];
NSMutableDictionary *productCategories = [[NSMutableDictionary alloc] init];
productCategories = [responseDict objectForKey:#"product_categories"];
NSLog(#"Response %# ", productCategories);
self.responseJSON = responseDict;
if ([self.responseJSON isKindOfClass:[NSDictionary class]]){ //Added instrospection as suggested in comment.
dictionaryArray= [self.responseJSON objectForKey:#"product_categories"];
if ([dictionaryArray isKindOfClass:[NSArray class]]){
//Added instrospection as suggested in comment.
for (NSDictionary *dictionary in dictionaryArray) {
CategoryBO *categoryBO = [[CategoryBO alloc] init];
categoryBO.categoryName = [dictionary objectForKey:#"name"];
categoryBO.categoryProductId = [dictionary objectForKey:#"id"];
categoryBO.categoryParentID = [dictionary objectForKey:#"parent"];
[newArray addObject:categoryBO];
}
}
}
NSLog(#"Data Array: %#",newArray);
for(int i = 0; i<[newArray count];i++)
{
NSLog(#"%#",[[newArray objectAtIndex:i] categoryName]);
[self.dataModelArray addObject:[[newArray objectAtIndex:i] categoryName]] ;
}
NSLog(#"Data %#", self.dataModelArray);
[self.expandableTableView reloadData];
});
} failure:^(NSError *error) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)expandableTableView:(APExpandableTableView *)tableView numberOfChildrenForGroupAtIndex:(NSInteger)groupIndex {
return [[self.dataModelArray objectAtIndex:groupIndex] count] - 1;
}
- (NSInteger)numberOfGroupsInExpandableTableView:(APExpandableTableView *)tableView {
return [self.dataModelArray count];
}
- (UITableViewCell *)expandableTableView:(APExpandableTableView *)tableView cellForChildAtIndex:(NSInteger)childIndex groupIndex:(NSInteger)groupIndex {
NSString *cellIdentifier = #"SampleChildCell";
UITableViewCell *cell = [self.expandableTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:childIndex + 1];
return cell;
}
- (UITableViewCell *)expandableTableView:(APExpandableTableView *)tableView cellForGroupAtIndex:(NSInteger)groupIndex {
NSString *cellIdentifier = #"SampleGroupCell";
UITableViewCell *cell = [self.expandableTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:0];
return cell;
}
- (void)expandableTableView:(APExpandableTableView *)tableView deleteChildAtIndex:(NSInteger)childIndex groupIndex:(NSInteger)groupIndex {
[[self.dataModelArray objectAtIndex:groupIndex] removeObjectAtIndex:childIndex + 1];
}
- (void)expandableTableView:(APExpandableTableView *)tableView moveChildAtIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex groupIndex:(NSInteger)groupIndex {
NSString *moveObject = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:sourceIndex + 1];
[[self.dataModelArray objectAtIndex:groupIndex] removeObjectAtIndex:sourceIndex + 1];
[[self.dataModelArray objectAtIndex:groupIndex] insertObject:moveObject atIndex:destinationIndex + 1];
}
- (void)expandableTableView:(APExpandableTableView *)tableView moveGroupAtIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex {
NSMutableArray *moveObject = [self.dataModelArray objectAtIndex:sourceIndex];
[self.dataModelArray removeObjectAtIndex:sourceIndex];
[self.dataModelArray insertObject:moveObject atIndex:destinationIndex];
}

UISegmentedControl in iOS

I am using UISegmentedControl and using UITableView but my query is segment button 1 click and display data for yes and 2 button click and display data from no and adding A to Z section UITableView first button click properly data display and properly tableview section atoz display but 2 button click and app crash `
 #import "ZnameViewController.h"
#import "ZpaleoViewController.h"
#import "SWRevealViewController.h"
#interface ZnameViewController ()
#end
#implementation ZnameViewController
#synthesize strname1,sagmentController,objtbl,name;
- (void)viewDidLoad {
[super viewDidLoad];
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.slide setTarget: self.revealViewController];
[self.slide setAction: #selector( revealToggle: )];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
databse = [FMDatabase databaseWithPath:appdelegate.appDBPath];
[arrCatname removeAllObjects];
[arrPaleo removeAllObjects];
arrCatname = [[NSMutableArray alloc]init];
arrPaleo = [[NSMutableArray alloc]init];
arrStatus = [[NSMutableArray alloc]init];
arrCat2 = [[NSMutableArray alloc]init];
arrSta2 = [[NSMutableArray alloc]init];
[self segmentSwitch:self];
// Do any additional setup after loading the view.
}
- (IBAction)segmentSwitch:(id)sender {
[databse open];
NSString *selectQuery = [NSString stringWithFormat:#"select * from Food ORDER BY name ASC"];
NSLog(#"%#",selectQuery);
FMResultSet *resultQuary = [databse executeQuery:selectQuery];
while ([resultQuary next]) {
// NSString *z_paleo = [resultQuary stringForColumn:#"status"];
z_paleo = [NSString stringWithFormat:#"%d",[resultQuary intForColumn:#"status"]];
if ([z_paleo isEqualToString:#"1"]) {
if(z_name == nil || [z_name isKindOfClass:[NSNull null]])
{
[arrPaleo addObject:#""];
}
else{
[arrPaleo addObject:z_name];
}
[arrSta2 addObject:z_paleo];
}
else{
if(z_name == nil || [z_name isKindOfClass:[NSNull null]])
{
[arrCatname addObject:#""];
}
else
{
[arrCatname addObject:z_name];
}
[arrCat2 addObject:z_paleo];
}
}
[databse close];
if(sagmentController.selectedSegmentIndex == 0)
{
if ([z_paleo isEqualToString:#"1"]) {
[self getName:arrPaleo];
objtbl.hidden = NO;
}
}
else if (sagmentController.selectedSegmentIndex == 1)
{
if ([z_paleo isEqualToString:#"0"]) {
[self getName:arrCatname];
objtbl.hidden = NO;
}
}
[objtbl reloadData];
}
-(void)getName:(NSMutableArray *)arr
{
NSMutableArray *temp = [[NSMutableArray alloc] init];
NSMutableArray *temp2 = [[NSMutableArray alloc] init];
for(int i = 0; i < arr.count; i++)
{
NSString *string = [arr objectAtIndex:i];
dict = [[NSMutableDictionary alloc] init];
[dict setObject:string forKey:#"Name"];
[dict setObject:[NSNumber numberWithInt:i] forKey:#"ID"];
NSString *firstString = [string substringToIndex:1];
if([temp2 containsObject:firstString] == NO || temp2.count == 0)
{
if(temp2.count != 0)
{
[temp addObject:temp2];
temp2 = [[NSMutableArray alloc] init];
}
[temp2 addObject:firstString];
}
[temp2 addObject:dict];
}
[temp addObject:temp2];
sorted = [[NSArray alloc] initWithArray:temp];
}
-(void)getname2:(NSMutableArray *)array{
NSMutableArray *temp = [[NSMutableArray alloc] init];
NSMutableArray *temp2 = [[NSMutableArray alloc] init];
for(int i = 0; i < array.count; i++)
{
NSString *string = [array objectAtIndex:i];
dict1 = [[NSMutableDictionary alloc] init];
[dict1 setObject:string forKey:#"Name"];
[dict1 setObject:[NSNumber numberWithInt:i] forKey:#"ID"];
NSString *firstString = [string substringToIndex:1];
if([temp2 containsObject:firstString] == NO || temp2.count == 0)
{
if(temp2.count != 0)
{
[temp addObject:temp2];
temp2 = [[NSMutableArray alloc] init];
}
[temp2 addObject:firstString];
}
[temp2 addObject:dict1];
}
[temp addObject:temp2];
sorted1 = [[NSArray alloc] initWithArray:temp];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
int i = 0;
for(NSArray *array in sorted)
{
NSString *string = [array objectAtIndex:0];
if([string compare:title] == NSOrderedSame)
break;
i++;
}
return i;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (sagmentController.selectedSegmentIndex == 0) {
return [sorted count];
}else {
return [sorted count];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSArray *array = [sorted objectAtIndex:section];
return [array objectAtIndex:0];
//return [foodIndexTitles objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *titleArray = [NSMutableArray array];
[titleArray addObject:#"A"];
[titleArray addObject:#"B"];
[titleArray addObject:#"C"];
[titleArray addObject:#"D"];
[titleArray addObject:#"E"];
[titleArray addObject:#"F"];
[titleArray addObject:#"G"];
[titleArray addObject:#"H"];
[titleArray addObject:#"I"];
[titleArray addObject:#"J"];
[titleArray addObject:#"K"];
[titleArray addObject:#"L"];
[titleArray addObject:#"M"];
[titleArray addObject:#"N"];
[titleArray addObject:#"O"];
[titleArray addObject:#"P"];
[titleArray addObject:#"Q"];
[titleArray addObject:#"R"];
[titleArray addObject:#"S"];
[titleArray addObject:#"T"];
[titleArray addObject:#"U"];
[titleArray addObject:#"V"];
[titleArray addObject:#"W"];
[titleArray addObject:#"X"];
[titleArray addObject:#"Y"];
[titleArray addObject:#"Z"];
return titleArray;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (sagmentController.selectedSegmentIndex == 1) {
NSArray *array = [sorted objectAtIndex:section];
return (array.count - 1);
}else{
NSArray *array = [sorted objectAtIndex:section];
return (array.count - 1);
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifire = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifire];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifire];
}
if (sagmentController.selectedSegmentIndex == 0) {
NSArray *array = [sorted objectAtIndex:indexPath.section];
dict = [array objectAtIndex:indexPath.row + 1];
cell.textLabel.text = [dict objectForKey:#"Name"];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Yes_check.png"]];
[cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];
}
else
{
NSArray *array = [sorted objectAtIndex:indexPath.section];
dict = [array objectAtIndex:indexPath.row + 1];
cell.textLabel.text = [dict objectForKey:#"Name"];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"No.png"]];
[cell.accessoryView setFrame:CGRectMake(0, 0, 15, 15)];
return cell;
}
return cell;
}

tableview crash with '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

I got a problem.
I have a TableView in my ViewController. This TableView has 5 rows with textFields. The height of each row is 156 pixels. also I have button "Save", and after click I want save all my data to NSMutableArray in following method, but in result I got an error.
What should I do in this way?
thank you
my method example:
- (void) saveDataToArray
{
carCellTableViewCell * cell;
_carNewPrices = [[NSMutableArray alloc] init];
for (int i = 0; i < 5; i++)
{
cell = (carCellTableViewCell *)[_meTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[_carPrices addObject:cell.priceText.text];
}
}
and here is cellForRowAtIndexPath:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
carCellTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
cell.nameLabel.text = [_carNames objectAtIndex:indexPath.row];
cell.priceLabel.text = [NSString stringWithFormat:#"$%#/day",[_carPrices objectAtIndex:indexPath.row]];
cell.infoLabl.text = [_carInfos objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
{
[cell.img setImage:[UIImage imageNamed:#"rolls.jpg"]];
return cell;
}
case 1:
{
[cell.img setImage:[UIImage imageNamed:#"bentley.jpg"]];
return cell;
}
case 2:
{
[cell.img setImage:[UIImage imageNamed:#"mercedes.jpg"]];
return cell;
}
case 3:
{
[cell.img setImage:[UIImage imageNamed:#"bmw.jpg"]];
return cell;
}
case 4:
{
[cell.img setImage:[UIImage imageNamed:#"skoda.jpg"]];
}
default:
break;
}
return cell;
}
additional:
in my tableviewCell i have a label, and a textfield. when i click on "Save" i want save all my data from textField and send it to label.
here is all code from .m file:
#import "carListViewController.h"
#import "carCellTableViewCell.h"
#import "UserSingleton.h"
#import "CheckInternetConnection.h"
#define getCarList #"http:mylink.php" //changed
#define setCarList #"http:mylink.php" //changed
#interface carListViewController ()
#property (weak, nonatomic) IBOutlet UIBarButtonItem *editButtonOutler;
- (IBAction)editButtonOnClick:(id)sender;
#property BOOL editOrSave;//0 when edit, 1 when save
#property UserSingleton * userInfo;
#property NSMutableArray *json;
#property NSMutableArray * carNames;
#property NSMutableArray * carPrices;
#property NSMutableArray * carInfos;
#property NSMutableArray * carNewPrices;
- (void) setData;
#property (weak, nonatomic) IBOutlet UITableView *meTableView;
- (void) saveDataToArray;
- (void) getDataOfCars;
#end
#implementation carListViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"List of cars";
// Do any additional setup after loading the view.
}
- (void) viewWillAppear:(BOOL)animated
{
CheckInternetConnection * checkInternet = [[CheckInternetConnection alloc] init];
if (![checkInternet isInternetAvailable])
[self.navigationController popViewControllerAnimated:YES];
_userInfo = [UserSingleton sharedInstance];
if (_userInfo.priority == 2)
{
_editButtonOutler.enabled = YES;
_editButtonOutler.title = #"Edit";
}
else
{
_editButtonOutler.enabled = NO;
_editButtonOutler.title = #"";
}
_editOrSave = NO;
[self getDataOfCars];
[_meTableView reloadData];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
carCellTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
cell.nameLabel.text = [_carNames objectAtIndex:indexPath.row];
cell.priceLabel.text = [NSString stringWithFormat:#"$%#/day",[_carPrices objectAtIndex:indexPath.row]];
cell.infoLabl.text = [_carInfos objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
{
[cell.img setImage:[UIImage imageNamed:#"rolls.jpg"]];
return cell;
}
case 1:
{
[cell.img setImage:[UIImage imageNamed:#"bentley.jpg"]];
return cell;
}
case 2:
{
[cell.img setImage:[UIImage imageNamed:#"mercedes.jpg"]];
return cell;
}
case 3:
{
[cell.img setImage:[UIImage imageNamed:#"bmw.jpg"]];
return cell;
}
case 4:
{
[cell.img setImage:[UIImage imageNamed:#"skoda.jpg"]];
}
default:
break;
}
return cell;
}
- (IBAction)editButtonOnClick:(id)sender {
if (_editOrSave == 0)
{
_editOrSave = 1;
_editButtonOutler.title = #"Save";
carCellTableViewCell * cell;
for (int i = 0; i < 5; i ++)
{
cell = (carCellTableViewCell *)[_meTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
cell.priceLabel.hidden = YES;
cell.priceText.hidden = NO;
cell.priceText.text = [[_json objectAtIndex:i] objectForKey:#"cost"];
}
}
else if (_editOrSave == 1)
{
_editOrSave = 0;
carCellTableViewCell * cell;
for (int i = 0; i < 5; i ++)
{
cell = (carCellTableViewCell *)[_meTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
cell.priceLabel.hidden = NO;
cell.priceText.hidden = YES;
[self saveDataToArray];
[self setData];
//cell.priceLabel.text = [_carPrices objectAtIndex:i];
}
_editButtonOutler.title = #"Edit";
}
[self getDataOfCars];
[_meTableView reloadData];
}
- (void) getDataOfCars
{
_carInfos = [[NSMutableArray alloc] init];
_carNames = [[NSMutableArray alloc] init];
_carPrices = [[NSMutableArray alloc] init];
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:getCarList] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
_json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
carCellTableViewCell * cell;
for (int i = 0; i < _json.count; i ++)
{
cell = (carCellTableViewCell *)[_meTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[_carNames addObject:[[_json objectAtIndex:i] objectForKey:#"name"]];
[_carPrices addObject:[[_json objectAtIndex:i] objectForKey:#"cost"]];
[_carInfos addObject:[[_json objectAtIndex:i] objectForKey:#"about"]];
}
}
- (void) setData{
for (int i = 0; i < 5; i ++)
{
NSMutableString * postString = [NSMutableString stringWithFormat:setCarList];
[postString appendString:[NSString stringWithFormat:#"?id=%d", i+1]];
[postString appendString:[NSString stringWithFormat:#"&cost=%#", [_carPrices objectAtIndex:i]]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:#"POST"];
NSURLConnection * postConnection;
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
}
- (void) saveDataToArray
{
carCellTableViewCell * cell;
_carNewPrices = [[NSMutableArray alloc] init];
for (int i = 0; i < 5; i++)
{
cell = (carCellTableViewCell *)[_meTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[_carPrices addObject:cell.priceText.text];
}
}
#end
it seems that an error is caused because not all cells are visible in the screen. after my scroll down now even last cell has changed after my onclick on edit button.
how to resovle this problem?
It's upside-down to fill an array with what's in a UITableView. The way to do that is the other way around.
In other words, somewhere else in your code you determine what's in the priceText label. If it's a static table, then the information might be in IB, or if you're implementing tableview:cellForRowAtIndexPath:, you're looking up the priceText there.
Put those values in the priceArray.
Your edit helped. This line:
[NSString stringWithFormat:#"$%#/day",[_carPrices objectAtIndex:indexPath.row]];
Is your friend, so:
NSMutableArray *newArrayOfStrings = [NSMutableArray array];
for (int i=0; i<_carPrices.count; i++) {
NSString *str = [NSString stringWithFormat:#"$%#/day",_carPrices[i]];
[newArrayOfStrings addObject:str];
}
Edit again. More code and comments, more clarity:
Declare that your vc implements the UITextFieldDelegate, and declare a property to keep your edited prices:
#interface MyViewController <UITextFieldDelegate>
#property (nonatomic, strong) NSMutableArray *editedStrings;
// initialize this with the carPrices after you get these from JSON
self.editedStrings = [_carPrices mutableCopy]; // if they are NSNumbers
// if they are strings, you'll need a deeper copy:
self.editedStrings = [NSMutableArray array];
for (NSString *str in _carPrices) {
[self.editedStrings addObject:[str copy]];
}
In cellForRowAtIndexPath, make your vc the delegate, and tag the textFields, so you know which one is being edited:
cell.priceLabel.delegate = self;
cell.priceLabel.tag = indexPath.row;
Then implement the delegate method for when the user edits:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSInteger index = textField.tag;
NSString *candidateString = [textField.text stringByReplacingCharactersInRange:range withString:string];
[self.editedStrings replaceObjectAtIndex:index withObject: candidateString];
return YES;
}
Add a breakpoint to the line [_carPrices addObject:cell.priceText.text] and you'll see that at some index, the text will be nil. I can't tell you why will it be nil, since I don't know how you're creating the cell.

Exception in UISearchBar

I'm trying to implement the searchBar following steps in this Video
But I got the following exception when I press the searchBar
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <Authors: 0x10960c1e0>.'
AuthorsTableViewController.h
#interface AuthorsTableViewController : UITableViewController <UISearchBarDelegate> {
NSMutableArray *authorsArray;
NSMutableArray *resultArray;
QuotesNavController *quotes;
}
#property (nonatomic, strong) IBOutlet UISearchBar *SearchBar;
#property (nonatomic, retain) NSMutableArray *authorsArray;
#property (nonatomic, retain) NSMutableArray *resultArray;
-(sqlite3 *) openDataBase;
-(IBAction)backToQuotes:(id)sender;
#end
AuthorsTableViewController.m
#import "AuthorsTableViewController.h"
#interface AuthorsTableViewController ()
#end
#implementation AuthorsTableViewController
#synthesize authorsArray, resultArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self retrieveDataFromSqlite];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction)backToQuotes:(id)sender{
[self performSegueWithIdentifier:#"backToQuotes" sender:sender];
}
-(sqlite3 *) openDataBase{
sqlite3 *database;
NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:#"SuccessQuotes" ofType:#"sqlite"];
if (sqlite3_open([sqLiteDb UTF8String], &database) != SQLITE_OK) {
NSLog(#"Failed to open database!");
}else{
NSLog(#"database opened!");
}
return database;
}
-(void) retrieveDataFromSqlite{
authorsArray = [[NSMutableArray alloc] init];
sqlite3 *myDatabase = [self openDataBase];
const char *sqlSelect = "SELECT *, COUNT(qu_author) AS count FROM authors JOIN quotes ON _auid = qu_author GROUP BY au_name ORDER BY au_name ASC";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(myDatabase, sqlSelect, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
int author_id = sqlite3_column_int(compiledStatement, 0);
NSString *au_name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 1)];
NSString *au_picture = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 2)];
int quotes_id = sqlite3_column_int(compiledStatement, 3);
NSString *quotes_content = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 4)];
int quotes_author = sqlite3_column_int(compiledStatement, 5);
NSString *quotes_favorite = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 6)];
int count = sqlite3_column_int(compiledStatement, 7);
Authors *authors = [[Authors alloc] initWithUniqueId:author_id au_name:au_name au_picture:au_picture quotes_id:quotes_id quotes_content:quotes_content quotes_author:quotes_author quotes_author:quotes_author quotes_favorite:quotes_favorite count:count];
[authorsArray addObject:authors];
} // while end
}// prepare end
sqlite3_finalize(compiledStatement);
sqlite3_close(myDatabase);
}
- (void) searchThroughtData {
self.resultArray = nil;
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:#"SELF like[c] %#",[NSString stringWithFormat:#"%#*",self.SearchBar.text]];
self.resultArray = [[self.authorsArray filteredArrayUsingPredicate:resultPredicate] mutableCopy];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.tableView) {
return [authorsArray count];
} else {
[self searchThroughtData];
return [resultArray count];
}
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self searchThroughtData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"authorCell";
AuthorsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[AuthorsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
Authors *temp_items;
if (tableView == self.tableView) {
temp_items = [self.authorsArray objectAtIndex:indexPath.row];
}else{
temp_items = [self.resultArray objectAtIndex:indexPath.row];
}
[cell.authorName setText:[NSString stringWithFormat:#"%#",temp_items.au_name]];
[cell.count setTitle:[NSString stringWithFormat:#"%d",temp_items.count] forState:UIControlStateNormal];
UIImage *theImage = [UIImage imageNamed:temp_items.au_picture];
cell.authorPic.image = theImage;
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithRed:93/255.0
green:45/255.0
blue:22/255.0
alpha:0.5];
cell.selectedBackgroundView = customColorView;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Authors *temp_items = [self.authorsArray objectAtIndex:indexPath.row];
quotes = [self.storyboard instantiateViewControllerWithIdentifier:#"QuotesNavController"];
quotes.quType = 3;
quotes.authorId = temp_items.author_id;
[self presentModalViewController:quotes animated:YES];
}
#end

UITableview cellForRowAtIndexPath method is not executing?

When i click search it executes a search class and after finding the results it executes numberOfRows method but then it is showing empty table. It is not executing cellForRowAtIndexPath method .
check my below code
code in viewcontroller.h
when i click search button this method will get executed
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
SearchResultsViewController *searchRes=[[SearchResultsViewController alloc]initWithNibName:#"SearchResultsViewController" bundle:nil];
NSString *searchQuery=[search text];
sharedManager=[Mymanager sharedManager];
sharedManager.searchQuery=searchQuery;
[searchRes searchString:searchQuery];
[self.navigationController pushViewController:searchRes animated:YES];
}
in search class
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(#"%#",results);
return [results count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.adjustsFontSizeToFitWidth = YES;
NSLog(#"indexpath%d",indexPath.row);
NSLog(#"%#",[results objectAtIndex:[indexPath row]]);
SearchResult* hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
NSLog(#"%#",hit.neighboringText);
cell.textLabel.text = [NSString stringWithFormat:#"...%#...", hit.neighboringText];
cell.detailTextLabel.text = [NSString stringWithFormat:#"Chapter %d - page %d", hit.chapterIndex, hit.pageIndex+1];
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12];
cell.textLabel.textColor = [UIColor colorWithRed:25/255.0 green:90/255.0 blue:100/255.0 alpha:1];
// else
// {
//
// }
// [[self resultsTableView] reloadData];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SearchResult* hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
[fvc loadSpine:hit.chapterIndex atPageIndex:hit.pageIndex highlightSearchResult:hit];
}
- (void) searchString:(NSString*)query{
// if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// {
self.results = [[NSMutableArray alloc] init];
[resultsTableView reloadData];
currentQuery=sharedManager.searchQuery;
//
[self searchString:currentQuery inChapterAtIndex:0];
//
// }else {
// currentQuery=sharedManager.searchQuery;
// [self searchString:currentQuery inChapterAtIndex:0];
//}
}
- (void) searchString:(NSString *)query inChapterAtIndex:(int)index{
currentChapterIndex = index;
sharedManager=[Mymanager sharedManager];
Chapter* chapter = [sharedManager.spineArray objectAtIndex:index];
NSLog(#"%d",chapter.text.length);
NSRange range = NSMakeRange(0, chapter.text.length);
NSLog(#"%#",sharedManager.searchQuery);
range = [chapter.text rangeOfString:sharedManager.searchQuery options:NSCaseInsensitiveSearch range:range locale:nil];
int hitCount=0;
while (range.location != NSNotFound) {
range = NSMakeRange(range.location+range.length, chapter.text.length-(range.location+range.length));
range = [chapter.text rangeOfString:sharedManager.searchQuery options:NSCaseInsensitiveSearch range:range locale:nil];
hitCount++;
}
if(hitCount!=0){
UIWebView* webView = [[UIWebView alloc] initWithFrame:chapter.windowSize];
[webView setDelegate:self];
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:chapter.spinePath]];
[webView loadRequest:urlRequest];
} else {
if((currentChapterIndex+1)<[sharedManager.spineArray count]){
[self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
} else {
fvc.searching = NO;
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(#"%#", error);
[webView release];
}
- (void) webViewDidFinishLoad:(UIWebView*)webView{
NSString *varMySheet = #"var mySheet = document.styleSheets[0];";
NSString *addCSSRule = #"function addCSSRule(selector, newRule) {"
"if (mySheet.addRule) {"
"mySheet.addRule(selector, newRule);" // For Internet Explorer
"} else {"
"ruleIndex = mySheet.cssRules.length;"
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc.
"}"
"}";
NSString *insertRule1 = [NSString stringWithFormat:#"addCSSRule('html', 'padding: 0px; height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width];
NSString *insertRule2 = [NSString stringWithFormat:#"addCSSRule('p', 'text-align: justify;')"];
NSString *setTextSizeRule = [NSString stringWithFormat:#"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')",[[sharedManager.spineArray objectAtIndex:currentChapterIndex] fontPercentSize]];
[webView stringByEvaluatingJavaScriptFromString:varMySheet];
[webView stringByEvaluatingJavaScriptFromString:addCSSRule];
[webView stringByEvaluatingJavaScriptFromString:insertRule1];
[webView stringByEvaluatingJavaScriptFromString:insertRule2];
[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
[webView highlightAllOccurencesOfString:sharedManager.searchQuery];
NSString* foundHits = [webView stringByEvaluatingJavaScriptFromString:#"results"];
NSLog(#"%#", foundHits);
NSMutableArray* objects = [[NSMutableArray alloc] init];
NSArray* stringObjects = [foundHits componentsSeparatedByString:#";"];
for(int i=0; i<[stringObjects count]; i++){
NSArray* strObj = [[stringObjects objectAtIndex:i] componentsSeparatedByString:#","];
if([strObj count]==3){
[objects addObject:strObj];
}
}
NSArray* orderedRes = [objects sortedArrayUsingComparator:^(id obj1, id obj2){
int x1 = [[obj1 objectAtIndex:0] intValue];
int x2 = [[obj2 objectAtIndex:0] intValue];
int y1 = [[obj1 objectAtIndex:1] intValue];
int y2 = [[obj2 objectAtIndex:1] intValue];
if(y1<y2){
return NSOrderedAscending;
} else if(y1>y2){
return NSOrderedDescending;
} else {
if(x1<x2){
return NSOrderedAscending;
} else if (x1>x2){
return NSOrderedDescending;
} else {
return NSOrderedSame;
}
}
}];
[objects release];
NSLog(#"%#",currentQuery);
for(int i=0; i<[orderedRes count]; i++){
NSArray* currObj = [orderedRes objectAtIndex:i];
SearchResult* searchRes = [[SearchResult alloc] initWithChapterIndex:currentChapterIndex pageIndex:([[currObj objectAtIndex:1] intValue]/webView.bounds.size.height) hitIndex:0 neighboringText:[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"unescape('%#')", [currObj objectAtIndex:2]]] originatingQuery:currentQuery];
[results addObject:searchRes];
NSLog(#"%#",results);
[searchRes release];
}
//Print results
for(int i=0;i<[results count];i++)
{
SearchResult* hit = (SearchResult*)[results objectAtIndex:i];
NSLog(#"%#",hit.neighboringText);
}
[resultsTableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
if((currentChapterIndex+1)<[sharedManager.spineArray count]){
[self searchString:sharedManager.searchQuery inChapterAtIndex:(currentChapterIndex+1)];
} else {
fvc.searching= NO;
}
[[self resultsTableView] reloadData];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//- (void)dealloc
////{
//// self.resultsTableView = nil;
//// //[results release];
//// //[currentQuery release];
//// [super dealloc];
//}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
resultsTableView=[[UITableView alloc]init];
[resultsTableView setDelegate:self];
[resultsTableView setDataSource:self];
sharedManager=[Mymanager sharedManager];
// Do any additional setup after loading the view from its nib.
results = [[NSMutableArray alloc] init];
self.navigationItem.title=#"Search ";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
self.navigationItem.backBarButtonItem=backButton;
[[UINavigationBar appearance] setTitleTextAttributes: #{
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor lightGrayColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:#"Trebuchet MS" size:15.0f]
}];
noMatchingSearch=[[NSArray alloc]initWithObjects:#"No Element Found", nil];
tableOfContents=[[NSMutableArray alloc]init];
for (id img in search.subviews)
{
if ([img isKindOfClass:NSClassFromString(#"UISearchBarBackground")])
{
[img removeFromSuperview];
}
}
tableOfContents=[sharedManager.List copy];
}
- (void)viewDidUnload
{
search = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
self.resultsTableView = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
MY SEARCH RESULTS
"<SearchResult: 0x113482c0>",
"<SearchResult: 0x11348a20>",
"<SearchResult: 0x88c0a50>"
The problem is with the search method before search the array is reinitialised and hence 0 returned in the resultArray and hence no value in tables
- (void) searchString:(NSString*)query{
self.results = [[NSMutableArray alloc] init];//Here it becomes 0!!
[resultsTableView reloadData];
currentQuery=sharedManager.searchQuery;
}
To make it right ,After the search is performed i believe
[self searchString:currentQuery inChapterAtIndex:0];
load the value in the result array and then reload table.
Make sure
in .h add
<UITableViewDataSource,UITableViewDelegate>
in nib
connect datasource and delegate[if via nib]

Resources