1
votes

I am trying to trigger a custom delegate method inside the delegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. Everything looks fine except I have never reached my custom delegate method which should be triggered by tapping a row. here is my implementation of delegation:

@class SettingsList;
@protocol SettingsListDelegate

- (void) retrieveSettings:(SettingsList*)tableController Nazov:(NSString*)Nazov;

@end


@interface SettingsList : UITableViewController {

    id        delegate;
}

@property (nonatomic, assign) id              delegate;

@end


@synthesize delegate;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *Nazov = [NSString stringWithString:[[self displayedObjects] objectAtIndex:indexPath.row]];

    NSLog(@"Vybral som %@", Nazov);
    [delegate retrieveSettings:self Nazov:Nazov];

}

The property definition of delegate is correct, but not visible on this site due to <> it is taking as a tag.

in the second class it is like this


@interface ShakeControl : UIViewController 

- (void) retrieveSettings:(SettingsList*)tableController Nazov:(NSString*)Nazov{

}

but never actually reach it in this case. Not sure what is wrong because use to delegate many times before and work fine and now stucked for hours...any help, will be appreciated ..thanks

1
Are you seeing the "NSLog(@"Vybral som %@", Nazov);" message? If you put a break point there, can you confirm that delegate is not nil?Zaky German
One thought: should it not read "self.delegate" in place of "delegate"? Also, check that you are in fact assigning the delegate somewhere.PengOne
Make sure,(using debugger) that delegate has memory allocated to it. I think, it is 0x0, this might be the reason it in not getting called. And I dont see the code where yor are assigning object to delegate. (like self.delegate = delegate)iHS
yes, PengOne/Harinder u r right guys, forgot with allocation to assign self into to the delegate property...thank youVanya

1 Answers

3
votes

You should do it like this: In header:

@protocol SomeControllerDelegate <NSObject>
@optional
  - (void) somethingSelected: (Anything *)selection;
@end
@interface SomeController : UITableViewController
{
  id <SomeControllerDelegate> delegate;
}
@property (nonatomic, retain) id<SomeControllerDelegate> delegate;

In code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self.delegate somethingSelected:(Anything *)data];
}

In another class - add to definition:

@interface ShakeControl : UIViewController <SomeControllerDelegate>