2015-06-21 45 views
0

我有兩個NSMuteableArray s。第一個(nameOfSectionArray)收集每個新節的名稱。第二個(numberOfRowsArray)收集每個部分應該有多少行。我在使用這些數組創建一個UITableView時遇到問題,它具有適當數量的行數正確的部分。用2行創建多個UITableView節NSMuteableArrays

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [nameOfSectionsArray count]; 
} 

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


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 
    return [nameOfSectionsArray objectAtIndex:section]; 
} 

該程序不會崩潰。我只是沒有得到任何行。所有部分都正確出來。有人能幫我用我的numberOfRowsInSection方法嗎?

謝謝!

回答

0

我想通了。我意識到我只是在創建一個NSMuteableArry,這個數字可以表示我有多少行。在未來這將是一個問題。

相反,我做了另一個NSMuteableArry,我爲每一行添加了一個對象。然後我把它添加到原始數字OfOfRowsArray

這就是我所做的。

-(void) newRows 
{ 

int i=0; 
UITableViewCell *cell = [[UITableViewCell alloc]init]; 
NSMutableArray *allCells = [[NSMutableArray alloc]init]; 

while (i<numberOfRows) 
{ 
    [allCells insertObject:cell atIndex:[allCells count]]; 
    i++; 
} 

[numberOfRowsArray insertObject:allCells atIndex:[numberOfRowsArray count]]; 
} 

然後

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

return [[numberOfRowsArray objectAtIndex:section] count]; 
} 

這並獲得成功:)