Reputation: 6451
I want two create 2 sections uitableview so I did the following code
- (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;
}
}
the problem is that it Enter here twice , even I say it contain only one row
if (indexPath.section == 0 ) {
any idea how to solve that
Upvotes: 0
Views: 250
Reputation: 5038
if (section == 0 ) {
return 1;
}
else {
return 9;
}
Also your code:
else if (indexPath.section == 0 && indexPath.row < [self.TXTFileList count] ){
You never generate cell for section == 1. seem will crash or wrong reusing cell
Upvotes: 3
Reputation: 5227
You don't return row numbers in numberOfRowsInSection
, you just enter a number, but return nothing.
Also,
if (section = 0 ) {
sets section
to 0, you want to use the ==
operator.
Upvotes: 4