我想要两个 create 2 sections uitableview 所以我做了以下代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@" I entered numberOfSectionsInTableView");
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section = 0 ) {
1;
}
else {
9;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSLog(@" I entered cellForRowAtIndexPath");
NSLog(@"the Caf files count is : %d",[self.CafFileList count] );
NSLog(@" the txt file %d",[self.TXTFileList count] );
if (indexPath.section == 0 ) { // Enter here twice , even I say it contain only one row
NSLog(@"////////////////////////Section 0 %d" , [indexPath row] );
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[[cell textLabel] setText:[self.TXTFileList objectAtIndex:[indexPath row] ] ];
return cell;
}
else if (indexPath.section == 0 && indexPath.row < [self.TXTFileList count] ){
NSLog(@"////////////////////////Section 1 %d" , [indexPath row] );
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[[cell textLabel] setText:[self.CafFileList objectAtIndex:[indexPath row]] ];
return cell;
}
}
问题是它在这里输入了两次,即使我说它只包含一行
if (indexPath.section == 0 ) {
想知道怎么解决吗
最佳答案
您不返回 numberOfRowsInSection
中的行号,您只是输入一个数字,但不返回任何内容。
此外,
if (section = 0 ) {
设置 section
为 0,你想使用 ==
运算符。
关于iphone - uitableview 行呈现奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397269/