2012-04-20 99 views
1

行我怎樣才能在不同的管理行不同,不,不段的?沒有行&部分是不固定的依賴於其他class.Suppose另一個表視圖如果XXX節頭那麼它包含5行,另一段包含頭4行。節頭是在表視圖帳戶標題從其它類無段沒有在泰伯維

回答

0

其真正簡單的,使用下面的tableView delegates-

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // return your another table view's array count here, on which no of sections depends. 
} 


// Customize the number of rows in the table view. 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // use like this 
    int noOfRows = 0; 

    if(section == 0) 
    { 
    noOfRows = x; 
    } 
    else if(section ==1) 
    { 
    noOfRows = y; 
    } 
    . 
    . 
    . 
    else 
{ 
    noOfRows = z; 
} 
return noOfRows; 
} 

的x,y,z是NSInteger的這裏

+0

嘿,我知道,方法yar..but我不能完全做到這一點我想 – success 2012-04-20 04:55:16

+0

我迷惑了abo呃我必須檢查的條件? – success 2012-04-20 04:57:49

+0

看到我的答案確切答案 – Ranga 2012-04-20 05:00:42

1

在表視圖委託方法;它具有:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return data.count; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [data objectAtIndex:section].count; 
} 

您可以在這兩種方法的段數和行數。

當然,你也必須將數據配置爲二維數組。

+0

傑森: - 我要檢查節also..because它不是解決üR右,但我必須做的一樣。如果(部分==「XXX」)返回data.count ..如果(部分==「YY」)返回不同的陣列數.. – success 2012-04-20 05:02:14

+0

@success傑森的答案是,你所需要的一個,如果你看的tableView -numberOfRowsInSection(第2組的代碼),它會檢查每個基於部分指數從數組記錄並返回其依賴於從其他類fecth記錄 – denil 2012-04-20 05:07:04

2
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 3; or [yourarray count] // 3 sections 0,1,2 
} 

對於不同勢部分不同numver行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the sections. 
    if( section == 0) // first section with 5 rows 
     return [[yourarray objectAtIndex:section] count]; 

    if( section == 1) // 2nd section with 4 rows 
     return [[yourarray objectAtIndex:section] count]; 

    if( section == 2) // 3rd section with 57rows 
     return [[yourarray objectAtIndex:section] count]; 



} 
+0

部分不固定的數量,所以我不能檢查這樣 – success 2012-04-20 05:04:00

+0

部分是從不同陣列fecth和所有行也紛紛不同的充陣列 – success 2012-04-20 05:05:50

0

試試這個

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    if (section == 0){ 
     return 5; 
    } 
    if (section == 1){ 
     return 10; 
    } 
    //etc. 
} 
1

希望它能幫助:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if( section == 0) 
    return [array count]; 

if( section == 1) 
    return [array2 count]; 

if( section == 2) 
    return [array3 count]; 
} 
+0

但在這裏如何動態地給這裏的值...例如: - 你有if(section == 0)。我不想在這裏硬編碼0,1,2的值。我不確定部分的總數。我們如何做到這一點,我們想要爲不同的部分動態返回行號? – 2012-05-02 14:30:15