我正在尝试编写一个简单的自定义委托来显示多选列表(在参考了各种在线教程、stackoverflow、Apple doc 之后),但是在我想使用委托的类中,我设置委托的行进入了无限循环当我运行它时。
UIListViewController(我在哪里声明协议) https://bitbucket.org/ikosmik/uilistviewcontroller/src/ddfcd140b52e6e59d84e58d34d601f8f850145a1/UIList/UIListViewController.h?at=master
我试图在名为 View_Exporter 的 UIViewController 中使用委托
#import <UIKit/UIKit.h>
#import "UIListViewController.h"
@interface View_Exporter : UIViewController <UIListViewDelegate, UIListViewDataSource>
@property (nonatomic, strong) IBOutlet UIView *viewForList;
@property (nonatomic, strong) UIListViewController *listViewController;
@end
View_Exporter.m
#import "View_Exporter.h"
@implementation View_Exporter
@synthesize arraySelectedList;
@synthesize viewForList;
@synthesize listViewController;
#pragma mark - UIListViewController Methods
-(NSArray *) itemsForList {
NSLog(@"View_Exporter itemsForList");
NSArray *array = [NSArray arrayWithObjects:@"Server", @"Memory", nil];
return array;
}
- (id)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.
self.listViewController = [[UIListViewController alloc] initWithNibName:@"UIListViewController" bundle:nil];
self.listViewController.listViewDelegate = self;
//[self.viewForList addSubview:self.listViewController.view];
self.listViewController.listViewDataSource = self;
}
@end
但是当我运行代码时, viewDidLoad 中的这一行似乎无限循环:
self.listViewController.listViewDelegate = self;
为什么会无限循环?从昨天开始我就在这件事上头破血流。不知道哪里出错了。有人可以帮忙吗?