关于 objectAtIndex 的 NSMutableArray 的 NSRangeException:0
NSRangeException for NSMutableArray regarding objectAtIndex: 0
我有一个 strange(至少对我来说是这样)的问题,我的 NSMutableArray 似乎认为 objectAtIndex:1
不存在,但它显然是从什么做的我可以在控制台输出中看到。
我提供了数组和冲突的代码。
你知道,这是在 UITableView cellForRowAtIndexPath
-- Interface
@property (nonatomic, strong) NSMutableArray *packages;
-- viewDidLoad
packages = [[NSMutableArray alloc] init];
NSMutableArray *package1 = [[NSMutableArray alloc] init];
[package1 addObject:@[@"iPhone Cases", @"9928898669"]];
[packages addObject:package1];
NSMutableArray *package2 = [[NSMutableArray alloc] init];
[package2 addObject:@[@"RGB Controller", @"33A4Q0446691"]];
[packages addObject:package2];
NSLog(@"Packages Array: %@", packages);
-- UITableViewCell
NSMutableArray *package = [packages objectAtIndex:indexPath.row];
NSLog(@"%@", package);
NSString *packageName = [NSString stringWithFormat:@"%@", [package objectAtIndex:0]];
NSString *trackingNumber = [NSString stringWithFormat:@"%@", [package objectAtIndex:1]];
cell.appName.text = packageName;
cell.appVersion.text = trackingNumber;
-- Console Output
2019-03-14 19:45:35.942580+1100 SilentParcel[28937:961776] Packages Array: (
(
(
"iPhone Cases",
9928898669
)
),
(
(
"RGB Controller",
33A4Q0446691
)
)
)
2019-03-14 19:45:35.975358+1100 SilentParcel[28937:961776] (
(
"iPhone Cases",
9928898669
)
)
感谢您的评论 ()
我的问题已解决。我仍然不明白为什么或如何修复它,但确实如此。所以谢谢@Larme
我有一个 strange(至少对我来说是这样)的问题,我的 NSMutableArray 似乎认为 objectAtIndex:1
不存在,但它显然是从什么做的我可以在控制台输出中看到。
我提供了数组和冲突的代码。
你知道,这是在 UITableView cellForRowAtIndexPath
-- Interface
@property (nonatomic, strong) NSMutableArray *packages;
-- viewDidLoad
packages = [[NSMutableArray alloc] init];
NSMutableArray *package1 = [[NSMutableArray alloc] init];
[package1 addObject:@[@"iPhone Cases", @"9928898669"]];
[packages addObject:package1];
NSMutableArray *package2 = [[NSMutableArray alloc] init];
[package2 addObject:@[@"RGB Controller", @"33A4Q0446691"]];
[packages addObject:package2];
NSLog(@"Packages Array: %@", packages);
-- UITableViewCell
NSMutableArray *package = [packages objectAtIndex:indexPath.row];
NSLog(@"%@", package);
NSString *packageName = [NSString stringWithFormat:@"%@", [package objectAtIndex:0]];
NSString *trackingNumber = [NSString stringWithFormat:@"%@", [package objectAtIndex:1]];
cell.appName.text = packageName;
cell.appVersion.text = trackingNumber;
-- Console Output
2019-03-14 19:45:35.942580+1100 SilentParcel[28937:961776] Packages Array: (
(
(
"iPhone Cases",
9928898669
)
),
(
(
"RGB Controller",
33A4Q0446691
)
)
)
2019-03-14 19:45:35.975358+1100 SilentParcel[28937:961776] (
(
"iPhone Cases",
9928898669
)
)
感谢您的评论 (
我的问题已解决。我仍然不明白为什么或如何修复它,但确实如此。所以谢谢@Larme