我在将NSInteger
课程发送到另一堂课时遇到麻烦。这是我在做什么。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
NSInteger tag = cell.tag;
impact* myScript = [[impact alloc] init];
[myScript startProcess:tag];
}
在此,我向NSInteger
影响的startProcess
方法发送一个。问题是通过它发送时出现以下错误:
No visible @interface for 'impact' declares the selector 'startProcess:'
但问题是我正在定义startProcess
方法。
这是impact.h
文件:
-(NSInteger *)startProcess;
这是impact.m
文件:
#pragma mark - Table view delegate
- (void)startProcess:(NSInteger **)number {
[UITableView reloadData];
}
因此,回顾一下,我试图将an发送NSInteger
给另一个类的方法,而不是重新加载整个表。现在确定为什么我会收到此错误。
建议,想法?
您走在正确的道路上,但是您会注意到两个主要问题:
头文件中的声明与实现文件中的实现不匹配。方法的基本格式为:- (ReturnType)methodName:(<ParamType>)paramName;
在标头中,您定义的方法不带参数,并且返回NSInteger *
。在实现文件中,您将定义一个采用且不NSInteger **
返回任何值(void
)的方法。实施文件中的版本更接近您想要的版本。
NSInteger不是一个类,而是一个简单的类型。您不必像对象一样通过引用传递它,因此只需将参数指定NSInteger
为NSInteger *
或即可。NSInteger **
这使您可以在标头中包含以下代码:
- (void)startProcess:(NSInteger)number;
以及此代码在实现文件中
- (void)startProcess:(NSInteger)number {
[UITableView reloadData];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句