tableView:cellForRowAtIndexPath: only returning one custom uitableviewcell
I have been through my debugger and noticed my code will only return one customcell from my tableView:cellForRowAtIndexPath: method.. I don't know why or how to make it return both the customcells I want it to.. all it dose is display the same custom cell in both sections.
- 开发者_JAVA技巧(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
switch (section) {
case 0:
rows = 1;
break;
case 1:
rows = 1;
break;
}
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Registration Button
static NSString *CellIdentifier = @"CustomRegCell";
static NSString *CellNib = @"LogInCustomCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
//Registration Button
static NSString *CellButtonIdentifier = @"CustomSubmitCell";
static NSString *CellButtonNib = @"LogInCustomCell";
UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellButtonIdentifier];
if (cellButton == nil) {
NSArray *nibButton = [[NSBundle mainBundle] loadNibNamed:CellButtonNib owner:self options:nil];
cellButton = (UITableViewCell *)[nibButton objectAtIndex:0];
}
NSLog(@"%i", indexPath.section);
if (indexPath.section == 0) {
return cell; // jumps out of method here
}
if (indexPath.section == 1) {
return cellButton;
}
return nil;
}
try this one
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section==0)
{............
return cell;
}
else if(indexpath.section==1)
{
.....
return cellbutton;
}
}
精彩评论