我想要两个创建2个部分的UITableView 所以我做了以下代码的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) {
任何想法如何解决
如果(节= 0){?然后1; :-) – 2012-02-22 15:08:37
抱歉可以解释更多 – AMH 2012-02-22 15:14:02