我试图编写一个简单的自定义委托来显示多个选择列表(在引用各种在线教程,stackoverflow,Apple doc之后),但是在我想使用委托的类中,当我运行它时,我设置代理的行会进入无限循环。设置(自定义)委托运行到无限循环
UIListViewController(这里我声明协议) https://bitbucket.org/ikosmik/uilistviewcontroller/src/ddfcd140b52e6e59d84e58d34d601f8f850145a1/UIList/UIListViewController.h?at=master
,我试图使用委托在一个UIViewController称为View_Exporter
#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;
为什么会这样无限循环?从昨天开始,这件事让我感到头痛。不知道哪里出错。有人可以帮忙吗?
如果您的代码处于无限循环中,请使用调试器的暂停按钮或断点停止它,然后遍历代码以查看发生了什么。而且你无法命名自己的以UI开头的类,这是Apple的保留前缀,你可能会与私有API冲突。 – jrturton
让我用@jrturton调试器进行检查!谢谢你的评论。你说的话很有道理 - 我会改变用户界面的前缀。 – Jean