gpt4 book ai didi

ios - iCarousel + UITableView = cellForRowAtIndexPath indexPath 始终为空

转载 作者:行者123 更新时间:2023-11-29 02:57:01 26 4
gpt4 key购买 nike

我有一个让我头痛的问题。当我调用:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath`

我总是得到 indexPath=null 并出现以下错误。

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Categories copyWithZone:]: unrecognized selector sent to instance 0xc386b20'

我的 GallerySpirituosenViewController.h 中有这段代码:

@interface GallerySpirituosenViewController :  UIViewController <iCarouselDataSource, iCarouselDelegate , UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table_categories;
@property (weak, nonatomic) IBOutlet UITableView *table_brands;
@property (weak, nonatomic) IBOutlet UITableView *table_items;
@property (weak, nonatomic) IBOutlet iCarousel *carousel;
@property (weak, nonatomic) IBOutlet UIView *filtersContainer;
@end

稍后在我的 GallerySpirituosenViewController.m 中,我扩展了正常工作的“iCarrousel”,我有一个 View ,里面有 3 个 UITableView

在这里,我可以展示如何为一张表调用datasourcedelegate:

- (void)viewDidLoad
{
[super viewDidLoad];

self.table_brands.dataSource = self;
self.table_brands.delegate = self;

_carousel.type = iCarouselTypeCoverFlow2;
}

- (void)viewDidUnload
{
[super viewDidUnload];

//free up memory by releasing subviews
self.carousel = nil;
}

稍后是我填充表格的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [categories count];//arrays
}


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

// NSInteger carouselIndex = [self.carousel indexOfItemViewOrSubview:tableView];
// PersonData *data = [items objectAtIndex:carouselIndex];
static NSString *simpleTableIdentifier = @"SimpleTableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.textLabel.text = [categories objectAtIndex:indexPath.row];

return cell;
}

下面是对象类别的调试:

enter image description here

以及具有空值的 indexPath:

enter image description here

这里还有对象Category.h

#import <Foundation/Foundation.h>

@interface Categories : NSObject
@property (nonatomic, retain) NSString *id;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *sys_language_uid;
@end

和Category.m

#import "Category.h"

@implementation Categories

@synthesize id,title,sys_language_uid;


- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:id forKey:@"id"];
[encoder encodeObject:title forKey:@"title"];
[encoder encodeObject:sys_language_uid forKey:@"sys_language_uid"];
}

- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
self.id = [decoder decodeObjectForKey:@"id"];
self.title = [decoder decodeObjectForKey:@"title"];
self.sys_language_uid = [decoder decodeObjectForKey:@"sys_language_uid"];
}
return self;
}


@end

最佳答案

[categories objectAtIndex:indexPath.row] 返回类别对象。

你得到这样的字符串。

cell.textLabel.text = [类别objectAtIndex:indexPath.row].id

cell.textLabel.text = [类别 objectAtIndex:indexPath.row].title

编辑更多:

您应该像这样声明标题变量

@property(nonatomic,strong) NSString*title;

@property(nonatomic,copy) NSString*title;

关于ios - iCarousel + UITableView = cellForRowAtIndexPath indexPath 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23762186/

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