我想要兩個創建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