a custom delegate method inside didSelectRowAtInde

2019-08-04 19:02发布

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条回答
The star\"
2楼-- · 2019-08-04 20:04

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>
查看更多
登录 后发表回答