gpt4 book ai didi

iphone - TableView :cellForRowAtIndexPath: only returning one custom uitableviewcell

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:37 27 4
gpt4 key购买 nike

我已经通过我的调试器并注意到我的代码只会从我的tableView:cellForRowAtIndexPath: 方法..我不知道为什么或如何让它返回我想要的两个自定义单元格..它所做的只是在两个部分中显示相同的自定义单元格。

    - (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;
}

最佳答案

试试这个

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if(indexPath.section==0)
{............
return cell;
}
else if(indexpath.section==1)
{
.....
return cellbutton;
}
}

关于iphone - TableView :cellForRowAtIndexPath: only returning one custom uitableviewcell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5932640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com