DidSelectRowAtIndexPath not being called - iphone

I have 3 different detailTableViews that my cells in my masterTableView will call when touched.
Please see my master.m file:
#import "GuideTableViewController.h"
#import "GuideDetailTableViewController.h"
#import "GuideDetailTableViewController2.h"
#import "GuideDetailTableViewController3.h"
#import <QuartzCore/QuartzCore.h>
#interface GuideTableViewController (){
NSMutableData *weatherResponseData;
NSArray *headGuide;
NSArray *leftImages;
}
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property (weak, nonatomic) IBOutlet UIImageView *imgHeader;
#property (weak, nonatomic) IBOutlet UIImageView *ImgTitle;
#property (weak, nonatomic) IBOutlet UIImageView *ImgWeather;
#property (weak, nonatomic) IBOutlet UIButton *btnMap;
#property (weak, nonatomic) IBOutlet UILabel *LabelWeather;
#property (weak, nonatomic) IBOutlet UILabel *LabelWeather2;
#end
#implementation GuideTableViewController
//Weather method
- (void) loadWeather{
NSURLRequest *theRequest = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.wunderground.com/api/3919480da5014c98/conditions/q/BR/Sao_Sebastiao .json"]];
NSURLConnection *theConnection=[[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
if(theConnection){
weatherResponseData = [[NSMutableData alloc] init];
} else {
NSLog(#"failed");
}
}
//Delegates for WeatherData
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[weatherResponseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[weatherResponseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSString *msg = [NSString stringWithFormat:#"Failed: %#", [error description]];
NSLog(#"%#",msg);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:weatherResponseData options:NSJSONReadingMutableLeaves error:&myError];
NSArray *results = [res objectForKey:#"current_observation"];
NSString *cur = [results valueForKey:#"weather"];
NSString *tmp = [results valueForKey:#"temperature_string"];
NSString *wind = [results valueForKey:#"wind_string"];
NSLog(#"Current conditions: %#, %#º, %#", cur, tmp, wind);
self.LabelWeather.text = cur;
self.LabelWeather2.text = tmp;
}
//JSONmethod
- (void) loadJSON{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//code
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"https://dl.dropbox.com/u/100670549/guide.json"]];
NSError *error;
if (data)
{
headGuide = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
for (NSDictionary *dictionary in headGuide){
// NSLog([dictionary description]);
}
}else
{
NSLog(#"Could not load data");
}
dispatch_sync(dispatch_get_main_queue(), ^{
// code
[self.tableView reloadData];
});
});
}
//Load
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self loadJSON];
[self loadWeather];
leftImages = [NSArray arrayWithObjects:#"btn_Stay.png", #"btn_Eat.png", #"btn_Todo.png", nil];
// set background
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.jpg"]];
// rounded corners
[self.tableView.layer setCornerRadius:9.0];
[self.ImgWeather.layer setCornerRadius:9.0];
}
#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 headGuide.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
NSArray *dict = [headGuide objectAtIndex:indexPath.row];
cell.textLabel.text = [dict valueForKey:#"title"];
NSString *cellImage = [leftImages objectAtIndex:indexPath.row];
UIImage *cellIcon = [UIImage imageNamed:cellImage];
cell.imageView.image = cellIcon;
return cell;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"whereStay"]){
GuideDetailTableViewController *vc = [segue destinationViewController];
NSIndexPath *index = sender;
NSDictionary *dict = [headGuide objectAtIndex:index.row];
vc.stayGuide = dict;
}
else if ([segue.identifier isEqualToString:#"whereEat"]){
GuideDetailTableViewController2 *vc1 = [segue destinationViewController];
NSIndexPath *index = sender;
NSDictionary *dict = [headGuide objectAtIndex:index.row];
vc1.eatGuide = dict;
}
else if ([segue.identifier isEqualToString:#"whatTodo"]){
GuideDetailTableViewController3 *vc2 = [segue destinationViewController];
NSIndexPath *index = sender;
NSDictionary *dict = [headGuide objectAtIndex:index.row];
vc2.todoGuide = dict;
}
}
#pragma mark - tableView delegate
- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0){
[self performSegueWithIdentifier:#"whereStay" sender:indexPath];
}else if(indexPath.row ==1 ){
[self performSegueWithIdentifier:#"whereEat" sender:indexPath];
}else{
[self performSegueWithIdentifier:#"whatTodo" sender:indexPath];
}
[tableView setAllowsSelection:YES];
}
#end

Your method signature is also not properly capitalized:
- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath{
should be
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Method names are case sensitive.
Additionally, make sure you're setting the tableView's delegate with
self.tableView.delegate = self;

It doesn't look like you're setting this object as the delegate of your table view. In your -viewDidLoad method, you should call [[self tableView] setDelegate:self];

Where is your protocol for tableview delegate and datasource?
#interface GuideTableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
//Attributes...
IBOutlet UITableView *tableView;
}
in viewDidLoad, you should set the delegates:
tableView.delegate = self;
tableView.dataSource = self;
you could also set delegates in xib files...
So your delegates Methods should works... Check out with apple docs about tableview:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Related

reloadData wont call cellForRowAtIndexPath

I got myself in a problem that I cant find a solution to, so if someone can help me I would appreciate it. I've read a lot of posts on what could be the problem but I did not found any solution.
I have a .h
#interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
UITableView *myTableView;
}
#property (strong, nonatomic) UITableView *myTableView;
#end
and a .m
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize myTableView;
static NSString *CellIdentifier = #"CellIdentifier";
- (void)viewDidLoad
{
[super viewDidLoad];
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
myTableView.dataSource = self;
myTableView.delegate = self;
[self.view addSubview:myTableView];
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
myTableView.rowHeight = 325;
myTableView.backgroundColor = [UIColor yellowColor];
[myTableView setDelegate:self];
[myTableView setDataSource:self];
[myTableView registerClass:[MTTableViewCell class] forCellReuseIdentifier:CellIdentifier];
[self separateByType];
}
-(void)separateByType
{
NSURL *url = [NSURL URLWithString:tempUrl];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *response = [request responseString];
SBJsonParser *jsonReader = [SBJsonParser new];
firstJsonData = [NSMutableDictionary dictionary];
firstJsonData = [jsonReader objectWithString:response error:nil];
NSLog(#"Calling reloadData on %#", self.myTableView);
[self.myTableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[firstJsonData objectForKey:#"data"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MTTableViewCell *cell = (MTTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[MTTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.titleTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
[cell.descriptionTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
return cell;
}
First Of All , Your code should run well.
Be Sure that numberOfRowsInSection function should return valid number.
Be Sure that "myTableView" is not nil.
Be sure that "myTableView" is seen as background yellow?
Don't declare ivar UITableView *myTableView
Don't #synthesize myTableView
Always access myTableView via the property accessor self.myTableView
-(void)viewWillAppear:(BOOL)animated{
[self performSelector:#selector(reloadTable) withObject:nil afterDelay:0.2];
[self.tableView reloadData]; not working
}
- (void)reloadTable {
[self.tableView reloadData];
}
above code works for me reload table in selector method.

prepareforSegue tableViewCell to different detailTableViews

I´m having a tableView in a viewController with an array (3 labelTitles to 3 different detailViews). My problem is in the prepareForSegue-method, I dont really know how to call the detailViews. I use the correct segue identifiers names.
"master".m:
#import "GuideTableViewController.h"
#import "GuideDetailTableViewController.h"
#import "GuideDetailTableViewController2.h"
#import "GuideDetailTableViewController3.h"
#import <QuartzCore/QuartzCore.h>
#import "customImageCell.h"
#interface GuideTableViewController (){
NSMutableData *weatherResponseData;
NSArray *titleLabels;
NSArray *imagesLeft;
}
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property (weak, nonatomic) IBOutlet UIImageView *imgHeader;
#property (weak, nonatomic) IBOutlet UIImageView *ImgTitle;
#property (weak, nonatomic) IBOutlet UIImageView *ImgWeather;
#property (weak, nonatomic) IBOutlet UIButton *btnMap;
#property (weak, nonatomic) IBOutlet UILabel *LabelWeather;
#property (weak, nonatomic) IBOutlet UILabel *LabelWeather2;
#end
#implementation GuideTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//Weather method
- (void) loadWeather{
NSURLRequest *theRequest = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.wunderground.com/api/3919480da5014c98/conditions/q/BR/Sao_Sebastiao.json"]];
NSURLConnection *theConnection=[[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
if(theConnection){
weatherResponseData = [[NSMutableData alloc] init];
} else {
NSLog(#"failed");
}
}
//Delegates for WeatherData
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[weatherResponseData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[weatherResponseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSString *msg = [NSString stringWithFormat:#"Failed: %#", [error description]];
NSLog(#"%#",msg);
}
//All the data was loaded, let's see what we've got...
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:weatherResponseData options:NSJSONReadingMutableLeaves error:&myError];
NSArray *results = [res objectForKey:#"current_observation"];
NSString *cur = [results valueForKey:#"weather"];
NSString *tmp = [results valueForKey:#"temperature_string"];
NSString *wind = [results valueForKey:#"wind_string"];
NSLog(#"Current conditions: %#, %#º, %#", cur, tmp, wind);
self.LabelWeather.text = cur;
self.LabelWeather2.text = tmp;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self loadWeather];
titleLabels = [NSArray arrayWithObjects:#"Where to stay",#"Where to eat",#"What to do",nil];
imagesLeft = [NSArray arrayWithObjects:#"btn_Stay.png", #"btn_Eat.png", #"btn_Todo.png", nil];
//set background
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.jpg"]];
//rounded corners
[self.tableView.layer setCornerRadius:9.0];
[self.ImgWeather.layer setCornerRadius:9.0];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return titleLabels.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
customImageCell *cell = (customImageCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *cellLabel = [titleLabels objectAtIndex:indexPath.row];
cell.titleLabel.text = cellLabel;
NSString *cellImage = [imagesLeft objectAtIndex:indexPath.row];
UIImage *cellIcon = [UIImage imageNamed:cellImage];
cell.imageLeft.image = cellIcon;
return cell;
}
//To detailTableViewController
- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0){
[self performSegueWithIdentifier:#"stay" sender:self];
}else if(indexPath.row ==1 ){
[self performSegueWithIdentifier:#"eat" sender:self];
}else{
[self performSegueWithIdentifier:#"todo" sender:self];
}
}
- (void) viewWillAppear:(BOOL)animated{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.tableView.indexPathForSelectedRow];
[cell setSelected:NO];
//Hide navbar
[self.navigationController setNavigationBarHidden:YES];
}
//Show navbar in detailView
-(void)viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO];
}
#end
change didselectRow
- (void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0){
[self performSegueWithIdentifier:#"stay" sender:self];
}else if(indexPath.row ==1 ){
[self performSegueWithIdentifier:#"eat" sender:self];
}else{
[self performSegueWithIdentifier:#"todo" sender:self];
}
}

TableView to detailTableView - one step behind

When I connect the my tableView to a detailtableView I get the the "error" that the detailtableView is one step behind. For example when clicking the 2nd cell in the mastertableView it show the 1st cell detailInformation. Hope you understand my problem.
See my .m.
#import "GuideTableViewController.h"
#import "GuideDetailTableViewController.h"
#interface GuideTableViewController (){
NSArray *guide;
}
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#end
#implementation GuideTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//JSONmetod
- (void) loadJSON{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//code
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"https://dl.dropbox.com/u/100670549/test.json"]];
NSError *error;
if (data)
{
guide = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
for (NSDictionary *dictionary in guide){
NSLog([dictionary description]);
}
}else
{
NSLog(#"Could not load data");
}
dispatch_sync(dispatch_get_main_queue(), ^{
// code
[self.tableView reloadData];
});
});
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Anropa json
[self loadJSON];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return guide.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
NSDictionary *dict = [guide objectAtIndex:indexPath.row];
cell.textLabel.text = [dict valueForKey:#"title"];
return cell;
}
//Till detailView
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"showStay"]){
GuideDetailTableViewController *tvc = [segue destinationViewController];
NSIndexPath *index = sender;
NSDictionary *dict = [guide objectAtIndex:index.row];
tvc.stay = dict;
}
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:#"showStay" sender:indexPath];
}
#end
Thanks in advance!
you used didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath Delegate method, common autocomplete mistake.

Reloading tableview after fetching asynchronous JSON data

I have used asynchronous JSON request and response to get some data. I want to populate it in a tableview. However, all I see is blank table cells. I tried doing a reloadData but it is not working. Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://strong-earth-32.heroku.com/stores.aspx"]];//asynchronous call
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(#"%#", error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
SBJsonParser *parser = [[SBJsonParser alloc]init];
resultData = [[parser objectWithString:responseString error:nil]copy];
NSArray *storeArray = [[NSArray alloc]init];
storeArray= [resultData objectForKey:#"stores"];
populatedStoreArray = [[NSMutableArray alloc]init];
images = [[NSMutableArray alloc] init];
...........
[populatedStoreArray addObject:tempStore];
}
[self.storeDetailsTable reloadData];
[parser release];
}
The tableview looks like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
StoreCell *cell = (StoreCell *) [tableView dequeueReusableCellWithIdentifier:#"StoreCell"];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"StoreCellView" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (StoreCell *) currentObject;
break;
}
}
}
Store *storeAtIndex = [populatedStoreArray objectAtIndex:[indexPath row]];
cell.storePhoneNumber.text = [storeAtIndex phone];
cell.storeAddress.text = [storeAtIndex address];
cell.storeImage.image = [images objectAtIndex:[indexPath row]];
return cell;
}
Some more of my code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [populatedStoreArray count];
}
The header file:
#interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *storeDetailsTable;
}
#property (nonatomic, retain) IBOutlet UITableView *storeDetailsTable;
#property (nonatomic, strong) NSDictionary *resultData;
#property (nonatomic, strong) NSMutableArray *populatedStoreArray;
#property (nonatomic, strong) NSMutableArray *images;
#property (nonatomic, strong) NSMutableData *responseData;
#end
Any pointers will be appreciated because everywhere I search, I'm told to use reloadData which is not working. In fact, xcode is not even prompting me when I use it.
Thank you.
Maybe you missed this line:
storeDetailsTable.delegate=self;

Problems trying to override methods in Objective-C (iPhone)

this my problem i have a class X that inherits UITableViewController class and a class Y that inherits the X class, when i try to override a method in the Y class the method in the X class is invoked... and i can't find references to understand what's happening... can anyone help me?
Thanks in advance!
Code!
mluListBuilder.h
#import <UIKit/UIKit.h>
#interface mluListBuilder : UITableViewController {
NSString *sListTitle;
NSString *sEntityName;
NSArray *aEntityProperties;
NSMutableArray *maListRecords;
NSManagedObjectContext *mocList;
NSFetchRequest *frListRecords;
NSEntityDescription *edListRecords;
NSArray *aOrderByProperties;
NSArray *aToolBarItems;
NSArray *aToolBarItemsActions;
}
#property (nonatomic, retain) NSString *sListTitle;
#property (nonatomic, retain) NSString *sEntityName;
#property (nonatomic, retain) NSArray *aEntityProperties;
#property (nonatomic, retain) NSMutableArray *maListRecords;
#property (nonatomic, retain) NSManagedObjectContext *mocList;
#property (nonatomic, retain) NSFetchRequest *frListRecords;
#property (nonatomic, retain) NSEntityDescription *edListRecords;
#property (nonatomic, retain) NSArray *aOrderByProperties;
#property (nonatomic, retain) NSArray *aToolBarItems;
#property (nonatomic, retain) NSArray *aToolBarItemsActions;
- (id) initWithStyle: (UITableViewStyle) style
listTitle: (NSString *) psListTitle
entityName: (NSString *) psEntityName
entityProperties: (NSArray *) paEntityProperties
orderListByProperties: (NSArray *) paOrderByProperties
toolBarItems: (NSArray *) paToolBarItems
toolBarItemsActions: (NSArray *) paToolBarItemsActions;
- (void)newRecord;
- (void)deleteRecord;
#end
mluListBuilder.m
#import "mluListBuilder.h"
#implementation mluListBuilder
#synthesize sListTitle,
sEntityName,
aEntityProperties,
maListRecords,
mocList,
frListRecords,
edListRecords,
aOrderByProperties,
aToolBarItems,
aToolBarItemsActions;
- (id) initWithStyle: (UITableViewStyle) style
listTitle: (NSString *) psListTitle
entityName: (NSString *) psEntityName
entityProperties: (NSArray *) paEntityProperties
orderListByProperties: (NSArray *) paOrderByProperties
toolBarItems: (NSArray *) paToolBarItems
toolBarItemsActions: (NSArray *) paToolBarItemsActions
{
sListTitle = psListTitle;
sEntityName = psEntityName;
aEntityProperties = paEntityProperties;
aOrderByProperties = paOrderByProperties;
aToolBarItems = paToolBarItems;
aToolBarItemsActions = paToolBarItemsActions;
if (self = [super initWithStyle:style]) {
}
return self;
}
- (void)viewDidLoad {
self.title = NSLocalizedString(sListTitle, nil);
if ([aToolBarItems count] > 0) {
NSMutableArray *maToolBarItems = [[NSMutableArray alloc] init];
self.navigationController.toolbarHidden = NO;
for (int i = 0; i < [aToolBarItems count]; i++) {
UIBarButtonItem * bbiToolBarItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString([aToolBarItems objectAtIndex:i], nil)
style:UIBarButtonItemStyleBordered
target:self
action:NSSelectorFromString([aToolBarItemsActions objectAtIndex:i])
];
[maToolBarItems addObject:bbiToolBarItem];
}
self.toolbarItems = maToolBarItems;
} else {
self.navigationController.toolbarHidden = YES;
}
if (mocList != nil) {
frListRecords = [[NSFetchRequest alloc] init];
NSSortDescriptor *sdListRecords = [[NSSortDescriptor alloc] initWithKey:#"name" ascending:YES];
[frListRecords setSortDescriptors:[[NSArray alloc] initWithObjects:sdListRecords, nil]];
edListRecords = [NSEntityDescription entityForName:sEntityName inManagedObjectContext:mocList];
[frListRecords setEntity:edListRecords];
NSError *errFetchRequest;
maListRecords = [[mocList executeFetchRequest:frListRecords error:&errFetchRequest] mutableCopy];
}
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
NSError *errFetchRequest;
maListRecords = [[mocList executeFetchRequest:frListRecords error:&errFetchRequest] mutableCopy];
[self.tableView reloadData];
if (self.navigationController.toolbarHidden == YES) {
if ([aToolBarItems count] > 0) {
self.navigationController.toolbarHidden = NO;
}
}
}
- (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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [maListRecords count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
for (UIView *vwExisting in cell.contentView.subviews) {
[vwExisting removeFromSuperview];
}
NSEntityDescription *edCurrentRecord = [maListRecords objectAtIndex:indexPath.row];
UILabel *lblCell = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 5.0, 280, 20.0)];
[lblCell setText:edCurrentRecord.name];
[cell.contentView addSubview:lblCell];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
}
- (void)dealloc {
[super dealloc];
}
- (void)newRecord {
NSLog(#"%#", [self class]);
}
- (void)deleteRecord {
}
#end
mluLawyerCaseSituationsList.h
#import <Foundation/Foundation.h>
#import "mluListBuilder.h";
#interface mluLawyerCaseSituationsList : mluListBuilder {
}
- (void)newRecord;
#end
mluLawyerCaseSituationsList.m
#import "mluLawyerCaseSituationsList.h"
#implementation mluLawyerCaseSituationsList
- (void)newRecord {
NSLog(#"%#", [self class]);
}
#end
Calling the mluLawyerCaseSituationsList
mluLawyerCaseSituationsList *vcCaseSituations = [[mluListBuilder alloc]
initWithStyle:UITableViewStylePlain
listTitle:#"titCaseSituations"
entityName:#"case_situations"
entityProperties:[[NSArray alloc] initWithObjects:#"name", nil]
orderListByProperties:[[NSArray alloc] initWithObjects:#"name", nil]
toolBarItems:[[NSArray alloc] initWithObjects:#"btNew", nil]
toolBarItemsActions:[[NSArray alloc] initWithObjects:#"newRecord", nil]
];
Output... :(
2009-12-17 17:30:02.726 mluLawyer[2862:20b] mluListBuilder
Hope it helps...
I’ve been looking through your code only briefly, but it seems obvious (from code and from the output) that you allocate an instance of class X (mluListBuilder).
Of course, you cannot expect to have a method of class Y (mluLawyerCaseSituationsList), performed when Y is derived from X and the object is of class X.
So, you have:
#interface X : UITableViewController
- (void) method;
#end
#interface Y : X
- (void) method;
#end
You are calling -method, but it is being invoked on X, not Y? Only way that can happen is if you have an instance of X instead of Y (or if someone is playing very silly buggers with the runtime -- unlikely).
Add NSLog(#"%#", [self class]); to the method implementations and see what the class of the instance really is!
You don't give us much information in your question, but the following is how it should work:
Class_X.h:
#interface Class_X : UITableViewController
{
}
- (void)someMethod;
#end
Class_X.m:
#import "Class_X.h"
#implementation Class_X
- (void)someMethod
{
NSLog(#"method in Class_X was called");
}
#end
Class_Y.h:
#import "Class_X.h"
#interface Class_Y : Class_X
{
}
- (void)someMethod;
#end
Class_Y.m:
#import "Class_Y.h"
#implementation Class_Y
- (void)someMethod
{
NSLog(#"method in Class_Y was called");
}
#end
Elsewhere:
#import "Class_Y.h"
...
Class_X * x_instance = [[Class_X alloc] init];
Class_Y * y_instance = [[Class_Y alloc] init];
[x_instance someMethod];
[y_instance someMethod];
[Class_Y release];
[Class_X release];
Output:
method in Class_X was called
method in Class_Y was called