2013-10-31 98 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]; 
}