我想按照這個教程結合:NSTableView的問題
http://andrehoffmann.wordpress.com/2009/09/03/phonebook-tutorial-for-dummiesxcode-3-1-3/
,但應用程序一直在運行時崩潰。
在IB我有一個NSBUtton,NSTableView的,NSArrayController的和NSObject的(命名的AppController)
的tableview中有3周的cols。廣告名稱,列和高度。
在AppController的對象我有名爲艙單和三個出口,btnLoadSheet,tblAdList和arrayController
在arrayController綁定一個動作我將它設置爲AppController中,並設置模式的關鍵路徑的fileList,這是一個NSMutableArray,我會通過我的表格數據。
在每個表格單元格中,我將它們綁定到arrayController並將模型關鍵路徑分別設置爲adName,adcol,adHeight。
appController.h看起來是這樣的:
#import <Cocoa/Cocoa.h>
@interface AppController : NSWindowController {
IBOutlet NSArrayController *arrayController;
IBOutlet NSButton *btnAdRunner;
IBOutlet NSButton *btnAddItem;
IBOutlet NSButton *btnDelteItem;
IBOutlet NSButton *btnLoadSheet;
IBOutlet NSButton *btnQuit;
IBOutlet NSTableView *tblAdList;
NSMutableArray* fileList;
}
@property (copy) NSMutableArray* fileList;
- (IBAction)AdRun:(id)sender;
- (IBAction)AddItem:(id)sender;
- (IBAction)DeleteItem:(id)sender;
- (IBAction)LoadSheet:(id)sender;
- (IBAction)QuitApp:(id)sender;
@end
appController.m:
#import "AppController.h"
@implementation AppController
@synthesize fileList;
- (IBAction)LoadSheet:(id)sender {
//define the ad array (this will be pulled from the run sheet
fileList = [NSMutableArray arrayWithObjects:@"Ad1, 1, 2.5", @"Ad2, 1, 3", @"Ad3, 2, 1", @"Ad4, 1, 2.5", @"Ad5, 2, 4", nil];
int i=0;
for(NSString* thisdatarow in fileList) {
//increase i
i++;
//make ad id
NSString* adID = [NSString stringWithFormat:@"ad%d", i];
//convert add data to an array from a string
NSArray* templist = [thisdatarow componentsSeparatedByString:@","];
//get ad items
NSString* adname = [templist objectAtIndex: 0];
NSString* adcols = [templist objectAtIndex:1];
NSString* adheight = [templist objectAtIndex:2];
//declare an array
NSMutableArray* temparray = [[NSMutableArray alloc] initWithObjects: adname, adcols, adheight];
//dump temp array into arrayController
[arrayController addObject:temparray];
}
}
@end
我得到的是怎麼回事在較大的圖片,但我迷路了,如何把它所有一起。我也不確定我是否正確構建了它。例如,當將arrayController綁定到appController時,模型關鍵路徑下拉菜單中只有自己作爲選項,我不得不手動添加fileList,這種類似於我的紅旗。另外,他正在從plist獲得表格col binding的模型關鍵路徑,我,呃,把它們從我的屁股上拉出來。我不會從plist中得到我的數據,只是一個文本文件,用回車符和逗號分隔。我是否會將其轉儲爲可變字典,以便我可以建立鍵/值關係並使用鍵進行綁定?
當應用程序編譯它出來確定。然後我點擊載荷表按鈕,然後轉動,旋轉死亡的沙灘球。我假設應用程序不知道我想要它做什麼或解決我要求它做什麼,並決定要死。
任何在正確的方向輕推將不勝感激。
您是否收到崩潰報告?如果是這樣,請將其編輯爲您的問題。如果沒有,您的應用程序是否掛起?如果發生了這種情況,請抽取樣本並將其編輯到您的問題中。 – 2010-10-20 23:20:21