NSArray和tableview可可应用程序

时间:2014-04-24 03:49:14

标签: xcode cocoa

我有NSArray个带有多个属性的对象的实例。我想知道如何在cocoa应用程序的tableview中显示实例的NSString和int属性。对不起,我是新来的。

卡旨在保存各张卡的属性。

deck旨在让NSArray包含卡片和名称,以便deckBuilderdeckConstruction引用。

deckBuilder用于根据其属性newDeck构建套牌实例。 (newDeck从所有可能的卡片开始,并在删除卡片条目的情况下复制以创建新的卡片

deckConstruction是用户界面,.xib包含一个表,该表应显示NSMutableArray中卡片的名称,卡片和NSMutableArray中的数字值,numberOf

我找不到关于如何从数组填充此表的来源。 (提供的代码包含这些对象的4个.h文件)

//This is the Card object
//  Card.h
//  ProjectJJ
//
//  Created by Guest User on 3/23/14.
//
//

#import <Foundation/Foundation.h>

@interface Card : NSObject
{
    //defining what makes up a card
    NSString *name;
    NSString *attribute;
    float level;
    NSString *type;
    NSString *info;
    float attack;
    float defence;
    float cardNum;
}

@property (readwrite) NSString *name;
@property (readwrite) NSString *attribute;
@property (readwrite) float level;
@property (readwrite) NSString *type;
@property (readwrite) NSString *info;
@property (readwrite) float attack;
@property (readwrite) float defence;
@property (readwrite) float cardNum;
- (void)cards;

@end


// this is the deck object
//  deck.h
//  Cardsim
//
//  Created by Guest User on 4/11/14.
//
//

#import <Foundation/Foundation.h>
#import "Card.h"
//the deck object for the users decks
@interface deck : NSObject
{
    NSString *deckName; // the deck name
    NSMutableArray *allCards;//will display in the interface all the cards in the database so the user can pick and choose from these
    NSArray *numCardsInDeck;//will be next allCards indicating the number of each of the cards in the database that the user has put into their deck
    NSMutableArray *cardsInDeck;//the acutal cards in thier deck
}

@property (readwrite) NSString *deckName;
@property (readwrite) NSArray *allCards;
@property (readwrite) Card *impendingFortress;
@property (readwrite) Card *fortressSoldier;
@property (readwrite) Card *fortressKnight;
@property (readwrite) Card *fortressArcher;
@property (readwrite) Card *fortressMage;
@property (readwrite) Card *appocalypticBeast;

- (void)setDeckCards:(NSArray *)c;

@end

// this is the NSWindowController
//  deckConstruction.h
//  Cardsim
//
//  Created by Guest User on 4/2/14.
//
//

#import <Cocoa/Cocoa.h>
#import "deckBuilder.h"
#import "deck.h"


@interface deckConstruction : NSWindowController
{
    NSMutableArray *decks;
    NSMutableArray *numberOf;
    deckBuilder *deckMaker;
}

@property (readwrite) NSString *deckName;

- (void)setDecks:(NSMutableArray *)a;

@end

//
//  deckBuilder.h
//  Cardsim
//
//  Created by Guest User on 4/18/14.
//
//

#import <Foundation/Foundation.h>
#import "deck.h"
#import "card.h"

@interface deckBuilder : NSObject
{
    deck *newDeck;
    NSArray *numCard;
}

- (deck *)conDeck;

@end

1 个答案:

答案 0 :(得分:0)

我也是新手,现在只使用Objective-c。

Cocoa中的新TableView是每个单元格中包含nsview的表。为每个单元格增加价值。您需要将依赖关系添加到管理视图的类中。

AppDelegate:< NSTableViewDataSource, NSTabViewDelegate>

请记住将表格链接到此课程。 你需要让talbe知道它有多少行

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
    return <number of row in the data>;
}

在实施中,您致电

- (NSView *)tableView:(NSTableView *)tableView 
   viewForTableColumn:(NSTableColumn *)tableColumn 
                  row:(NSInteger)row 
{
    NSTextField *result = [[NSTextField alloc] initWithFrame:[<your tableview> frame]];
    // Add your custom for the cell in here.
    return [result autorelease];
}

这将调用函数并遍历表中的每个单元格。 希望这有帮助。