gpt4 book ai didi

objective-c - 自定义函数内的空数组

转载 作者:行者123 更新时间:2023-12-03 18:02:27 36 4
gpt4 key购买 nike

我在主类中定义了一个 NSMutableArray


@interface EasyCustomTableController : UIViewController

{
UITableView *tableView;
UIImageView *imageView;
NSString *saveData;
NSMutableArray *products;
}

@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) NSMutableArray *products;
@property (nonatomic,retain) IBOutlet NSString *saveData;

在主 .m 中,所有属性均已合成,产品数组已填充到 viewDidLoad

我的问题是为什么这个数组在所有方法中都可用(我用它来填充我的表)



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:NSIndexPath *)indexPath

但我的自定义函数为空,该函数也在我的主类中


-(NSString *)saveData

NSLog(@"%d", [products count]);

return @"Array is empty";
}

提前致谢

莫菲

最佳答案

很可能,您的类有两个实例。通过调试和观察“ self ”来仔细检查它。

关于objective-c - 自定义函数内的空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4980006/

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