我確信有一個簡單的方法來解決這個問題,但我無法弄清楚。爲子視圖控制器設置代理
我得到了一個TabBarViewController與幾個視圖。在一些視圖中,我使用基於XML的內容加載了Tableviews。
我的XML解析器工作正常,我之前在單獨的Projectfile中測試過。 問題是,我的TableViewController,我創建了一個XMLAppDelegate來管理我的xmlfiles的解析,仍然將方法發送到我的項目的主委託文件。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainAppDelegate slices]: unrecognized selector sent to instance 0x6d1fd00'
就像錯誤信息顯示,他試圖將它發送到我的MainAppDelegate,而不是XMLAppDelegate。
我實現了XMLAppDelegate在我的控制文件和初始化委託這種方式:
我的控制器.h文件
#import <UIKit/UIKit.h>
@class XMLAppDelegate, NewsDetailViewController;
@interface NewsViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *newsTableView;
XMLAppDelegate *appDelegate;
NewsDetailViewController *ndvController;
}
@end
我控制器的.m文件
- (void)viewDidLoad {
[super viewDidLoad];
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
self.title = @"Slices";
}
控制器正在加載到TabBarView作爲separa te .xib文件。 在這個nib文件中,我將Delegate和Data Source連接到了我的XMLAppDelegate。
我仍然得到這個錯誤在日誌和應用程序崩潰,因爲我試圖切換到Tab希望在其中TableViewController。
希望你明白我的問題。也許有人可以告訴我我在做錯了,在這裏設置委託給我的XMLAppDelegate。
編輯:
爲了解釋什麼,我想做的事:
我有一個XMLParser的類來解析文件,切片類存儲元素和XMLAppDelegate。從這些文件我得到我的XML結果存儲在一個名爲「片」的數組。
要使用數組的元素將其顯示爲Table或textlabel,我將TableViewController連接到XMLAppDelegate(它使用XMLParser File解析我的XML文檔並將數據存儲在數組中)。
此數組的項目中的文件之前聲明爲這樣
@property (nonatomic, readwrite) NSInteger sliceID;
@property (nonatomic, retain) NSString *image;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *text;
字符串,但是就像我說的,解析器作品。 我認爲我的問題似乎是我請求了appDelegate.slices,但選擇器不是我的XMLAppDelgate。錯誤表示它使用主代表,它沒有任何xml委託文件的特性。
TabView加載NewsViewController,它調用XMLAppDelegate中的數組。 我實現了這些文件,將委託連接到TableView作爲數據源和委託,但似乎仍需要主委託。
這讓我發瘋。 該項目是一個偉大的健康汽車旅館的公司簡介。 我從CMS獲取內容爲XML文件,並需要從XMLAppDelegate訪問它們,以傳遞網站內容。
希望你明白我的壞英文。 ;)
好的,問題解決了。我在我的主AppDelegate中實現瞭解析器。之後,調用解析器方法。 ;) – DevZarak 2010-11-16 11:48:56