gpt4 book ai didi

ios - 将 TableView 添加到 UIViewController 显示 [__NSCFConstantString size] 错误

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

我正在将 tableView 添加到具有自定义大小的 viewController,即我正在定义其框架。我没有设置它的委托(delegate),因为我不希望 tableView 执行任何操作。即使我设置了它,错误也是一样的。现在这个 tableView 由一个 array 填充 的图像。当我运行该应用程序时,它会抛出 [__NSCFConstantString size] 异常。

这是我在做的事情

enter image description here

这是 viewDidLoad 中定义的 tableView 数据源。

    menuArray = [[NSArray alloc]initWithObjects:@"icone_what1c.jpg",@"icone_what3c.jpg", @"icone_what2c.jpg",@"icone_what4c.jpg" ,nil];

tableView 数据源方法。

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

cell.imageView.image = [menuArray objectAtIndex:indexPath.row];
return cell;
}

这是异常的总结。

    [__NSCFConstantString size]: unrecognized selector sent to instance 0x1e25c
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString size]: unrecognized selector sent to instance 0x1e25c'
*** First throw call stack:
(
0 CoreFoundation 0x01ce85e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018d88b6 objc_exception_throw + 44
2 CoreFoundation 0x01d85903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01cd890b ___forwarding___ + 1019
4 CoreFoundation 0x01cd84ee _CF_forwarding_prep_0 + 14
5 UIKit 0x0059343f -[UIImageView setImage:] + 389
6 AirMapp 0x0000f187 -[MainViewController tableView:cellForRowAtIndexPath:] + 375
7 UIKit 0x0052cd2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
8 UIKit 0x0052ce03 -[UITableView _createPreparedCellForGlobalRow:] + 69
9 UIKit 0x00511124 -[UITableView _updateVisibleCellsNow:] + 2378
10 UIKit 0x005245a5 -[UITableView layoutSubviews] + 213
11 UIKit 0x004a8dd

最佳答案

改变这一行

cell.imageView.image = [menuArray objectAtIndex:indexPath.row];

cell.imageView.image = [UIImage imageNamed:[menuArray objectAtIndex:indexPath.row]];

关于ios - 将 TableView 添加到 UIViewController 显示 [__NSCFConstantString size] 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20738304/

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