2013-10-31 123 views
1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    NSLog(@"Test1"); 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
    //#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
     NSLog(@"No. of sections- %d",section); 
     return [[[BNRItemStore sharedStore] allItems] count] ;//no. of rows 
    } 

在上述情況下,numberOfSectionsInTableView:方法被調用兩次之前調用tableView方法。我不明白爲什麼。問題與numberOfSectionsInTableView方法

另一件令我迷惑的事情是,當我將1作爲numberOfSectionsInTableView:方法中的段數返回時,爲什麼它不反映在- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section方法中?它相當於將其記錄爲0

以前是否將段參數更新爲1?我的意思是在運行時tableView:numberOfRowsInSection:方法在內部被調用,所以顯然section參數應該保持一定的值。

是不是這樣?

+4

段數的計數從0開始,所以如果你聲明你只有一個段,它的索引將爲零。這就是爲什麼你在cellForRow中看到0節的原因 –

回答

1

節數是部分TableView中&行&部分的索引從0

0

節和排在tableViews開始就像數組計數,他們從0開始,

0

嘗試像這樣,儘管返回1: -

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    NSLog(@"Test1"); 
    return [yourArray count]; 
}