gpt4 book ai didi

ios - 自定义 TableviewCell 中的按钮不接受该操作。当我点击重试按钮时,它会抛出 exc_bad_access 信号。

转载 作者:行者123 更新时间:2023-11-29 03:25:37 24 4
gpt4 key购买 nike

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0){
UITableViewCell* cell = nil;
if (indexPath.row < kTotalScreens) {
if ([self.tableCellsPrecreated count]>=kTotalScreens) {
cell = [self.tableCellsPrecreated objectAtIndex:indexPath.row];
}

}
return cell;
}else
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIDForHome];
if (indexPath.row < [_subActionArray count])
{
if(cell == nil)
{
cell = [self getCellForCategoryActionForRow];
NSLog(@"************cell %d created",indexPath.row);
}
GridViewController *controller = [self getControllerForCategoryActionCellAtIndex:indexPath.row
andCell:(TitleWithGridViewCell*)cell];
[self reloadDataForController:controller
contentCategory:((CategoryAction *)[_subActionArray objectAtIndex:indexPath.row]).category
cellView:(TitleWithGridViewCell*)cell];
}
return cell;
}
}


-(UITableViewCell*)getCellForCategoryActionForRow
{
TitleWithGridViewCell* cell = [[[NSBundle mainBundle]loadNibNamed:@"TitleWithGridViewCell" owner:self options:nil]objectAtIndex:0];
CGRect frameCell = cell.contentView.bounds;
frameCell.size.height = [cell heightOfCellForSubCellofSize:CellSizeSmall viewClass:[EntityCellView class] numRows:1];
[cell setFrame:frameCell];
cell.delegate = self;
cell.accessibilityLabel =[NSString stringWithFormat:@"Category Channels Grid"];
return cell;
}

-(GridViewController*)getControllerForCategoryActionCellAtIndex :(NSInteger)index andCell:(TitleWithGridViewCell*)cell
{
GridViewController* gridController = nil;
CellViewFactory *channelCellFactory = [[CellViewFactory alloc] initWithWantedCellSize:CellSizeSmall cellViewClass:[EntityCellView class]];
ChannelsForCategoryDataFetcher *channelsForCategoryDataFetcher = [ChannelsForCategoryDataFetcher new];
PrefetchingDataSource *dataSource = [PrefetchingDataSource createWithDataFetcher:channelsForCategoryDataFetcher];
dataSource.sortBy = ProgramSortByRatingCount;
dataSource.objectsPrPage = 6;
if (cell) {
gridController = [[GridViewController alloc] initWithGridView:[cell getGridView] gridCellFactory:channelCellFactory dataSource:dataSource];
gridController.delegate = self;
}
return gridController;
}

上面的代码创建一个自定义的tableviewcell和该单元格的 Controller 。每个单元格都包含一个重试按钮,在网络故障的情况下。表格显示所有数据和单元格都很好。但是在点击单元格中的重试按钮时,它会显示exc_bad_access。

最佳答案

在您的自定义单元格端,

1) 使自定义单元格的 .h 文件的协议(protocol)类似于

@protocol CustomCellDelegate
@optional
- (void)tryAgainButtonTappedOnCell:(id)sender;
@end

2) 在你的.h 文件中设置delegate 并在click 方法上设置Custom Cell 的按钮

@property (nonatomic, strong) id<CustomCellDelegate> delegate;
- (IBAction)tryAgainButtonTapped:(id)sender;

3) 在你的 .m 文件中,

- (IBAction)tryAgainButtonTapped:(id)sender {
[self.delegate tryAgainButtonTappedOnCell:self];
}

4) 将 IBAction 与按钮链接起来

5) 取消选中使用自定义单元格的自动布局

在您的 TableView 端,

1) 设置自定义单元格的委托(delegate)

@interface SomeViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, CustomCellDelegate>

2) 在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中,设置单元格的委托(delegate) cell.delegate=self

3) 根据您的需要实现新制作的委托(delegate)功能,即

- (void)tryAgainButtonTappedOnCell:(id)sender
{
//your logic
}

希望对你有帮助。

干杯

关于ios - 自定义 TableviewCell 中的按钮不接受该操作。当我点击重试按钮时,它会抛出 exc_bad_access 信号。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20487434/

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