2012-08-25 49 views
0

的數據集下面是一個代碼,並朝着結束,我試圖找出方法來計算在部分我如何找到numberOfRowsInSection的對象

的NS對象定義
// DataDefinition的行數。 ħ #進口

@interface DataDefinition : NSObject 
@property (nonatomic, retain) NSString *dataHeader; 
@property (nonatomic, retain) NSMutableArray *dataDetails; 

@end 

顯示屏標題部分 //DataDisplay.h #進口

#import "DataDefinition.h" 

@interface DataDisplay : UITableViewController 
@property (read write) NSInteger RowsCount; 
@property (strong, nonatomic) NSMutableArray *dataSet; 
@property (strong, atomic) DataDefinition *individualData; 

@end 

顯示屏實現部分

//DataDisplay.m 

@interface DataDisplay() 
@end 

@implementation DataDisplay 
@synthesize RowsCount; 
@synthesize dataSet; 
@synthesize individualData; 

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 

    individualData.dataHeader = @"Header1"; 
    individualData.dataDetails = [[NSMutableArray alloc] initWithObjects:@"Header1-Detail1", @"Header1-Detail2", @"Header1-Detail3", nil]; 
    RowsCount = [individualData.dataDetails count]; 
    [dataSet addObject:individualData]; 
    . 
    . 
    . 
    [dataSet addObject:individualData]; 

    self.title = @"DataDisplay"; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return [dataSet count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in sections. 
    return ????? 
} 
+0

閱讀FAQ:HTTP://stackoverflow.com/faq,要麼接受我的答案或寫你自己的答案,並接受它,讓人們知道這個問題已經得到解答... – tiguero

+0

我是新來的這個地方,很想接受你的答案。但是它需要按照Darren的寫法來糾正。順便說一句,我該如何接受你的回答 – user1509593

回答

0

首先,如果你沒有在你想顯示你沒有實現這個方法的數據集部分。否則,需要將數據存儲在一個NSMutableArray中,該NSMutableArray將是一個數組數組:這將基本上存儲每段的內容。

然後你可以想像你的每部分的項目數量的訪問是這樣的:

[self.yourarray objectAtIndex:段]計數]

編輯

根據你的源代碼,並從我們的代碼應該是討論:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in sections. 
    return [((DataDefinition*)[self.dataSet objectAtIndex:section]).dataDetails count] 
} 
+0

不會總是給我只是1.我想方法來訪問datadetails計數 – user1509593

+0

否爲eg [self.dataSet objectAtIndex:0]將返回您的第一部分的數組所以[[self.dataSet objectAtIndex:0] count]將返回你的第一部分的行數,所以2 – tiguero

+0

我現在已經爲第一部分數據添加了3個數據常量。 「Header1-Detail1」,@「Header1-Detail2」,@「Header1-Detail3」我需要計數3的部分0.所以[self.dataSet objectAtIndex:0]將返回第一部分的數組,如你所說。現在[[self.dataSet objectAtIndex:0] count]會給我什麼。會不會是3.我猜不是。讓我試試並返回 – user1509593