![](/img/trans.png)
[英]How can I get my loading label to show up when I click button to next view controller?
[英]when I click button in collection view, i I can't pass value to next view controller
我遇到一个问题。 我使用了集合视图设置更多按钮。 我需要单击按钮,并将索引值传递给“ NextViewController”。 但是当我单击按钮时。 它显示在下面的错误消息中。
我尝试找出错误所在。 但是我找不到。
有谁能给我一些提示吗?
非常感谢你。
========== 错误消息 ===========
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIViewController itemsArray:]:无法识别的选择器已发送到实例0x9e78220'
===================================
=========== ListViewController.m ==========
@interface ListViewController ()
{
NSMutableArray * itemsArray ;
}
end
...
... //itemsArray had some data from webesrvice
...
-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomizedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomizedCell" forIndexPath:indexPath];
NSInteger targetIndex = indexPath.row + indexPath.section*3;
if( targetIndex < itemsArray.count )
{
[cell.cateBtn setTitle:[[itemsArray objectAtIndex:targetIndex] itemName] forState:UIControlStateNormal];
cell.cateBtn.tag = targetIndex;
[cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
return cell;
}
-(void)jumpToNextView:(UIButton*)sender
{
[self performSegueWithIdentifier:@"MySegueName" sender:sender];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NextViewController *nextViewController =
segue.destinationViewController;
nextViewController. itemsArray = itemsArray;
}
-(BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if( targetIndex < itemsArray.count )
return YES;
else
return NO;
}
========== NextViewController.h =========
@interface NextViewController : UIViewController
@property (strong, nonatomic) NSMutableArray *itemsArray;
@end
我猜问题jumpToNextView
在这行中,您的按钮操作方法名称为: jumpToNextView
:
[cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
而是在选择器或更改方法名称中更改jumpToDrScheduleList:
-(void)jumpToNextView:(UIButton*)sender
{
[self performSegueWithIdentifier:@"MySegueName" sender:sender];
}
在storyboard
检查NextViewController
的类名称。 它应该是NextViewController
。 但是作为
我可以在崩溃日志中看到类名称为UIViewController和UIViewController与ItemsArray完全不同。
多数民众赞成在这里崩溃的原因。
修改这个
[cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
同
[cell.cateBtn addTarget:self action:@selector(jumpToDrScheduleList:) forControlEvents:UIControlEventTouchUpInside];
UIControlEventTouchUpInside的按钮和事件的选择器;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.