我有5個對象的NSArray。多節UITableView和NSArray
NSArray *tmpArry2 = [[NSArray alloc] initWithObjects:@"test1", @"test2", @"test3", @"test4", @"test5",nil];
我有4個部分(見截圖)
我想要做的就是展示
- test1的在首節
- TEST2和TEST3在第2節 表
- test4 in 3rd section
- test5 in 4th section
下面是我對他們每個人的index.row和index.section問題從
indexPath.row: 0 ... indexPath.section: 0
indexPath.row: 0 ... indexPath.section: 1
indexPath.row: 1 ... indexPath.section: 1
indexPath.row: 0 ... indexPath.section: 2
indexPath.row: 0 ... indexPath.section: 3
我希望用indexPath.section去在tmpArry2值達到,但我不能當然我該怎麼做。我想創建一個全局靜態int計數器= 0;並不斷增加它在cellForRowAtIndexPath但問題是,如果我上下滾動的值不斷跳轉單元格。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"Inside cellForRowAtIndexPath");
static NSString *CellIdentifier = @"Cell";
// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// If no cell is available, create a new one using the given identifier.
if (cell == nil)
{
// Use the default cell style.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSLog(@"indexPath.row: %d ... indexPath.section: %d ...", indexPath.row, indexPath.section);
//this will not give me right results
//NSString *titleStr2 = [tmpArry2 objectAtIndex:indexPath.section];
}
對不起 - 我有一個錯字。當我把它發佈在這裏時,我通常會啞口無言。我錯過了一些變數 –
固定錯字,對不起:) – Mert
謝謝你的出色簡單的答案!奇蹟般有效 –