我試圖編寫一個簡單的自定義委託來顯示多個選擇列表(在引用各種在線教程,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