我试图通过prepareWithSegue传递一个数组,但是当我启动应用程序时,它返回null。
这是代码:
这是 setAnArray 方法:
数据应该从嵌入有UINavigation Controller的viewController传递到PersonViewController(表视图),但在表格中没有显示任何内容,所以我记录了数组计数并发现它为零,所以我使用以下代码进行了进一步检查:
我收到了“数组为空”的消息,请帮我解决这个问题。
这是代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.destinationViewController isEqual:@"table"]) {
PersonsViewController *person= [[PersonsViewController alloc]init];
[person setAnArray:anArray];
person = segue.destinationViewController;
}
}
这是 setAnArray 方法:
-(void)setAnArray:(NSMutableArray *)anArray
{
array = [[NSMutableArray alloc]initWithArray:anArray];
if (array != nil) {
NSLog(@"array is copied !!");
}
}
数据应该从嵌入有UINavigation Controller的viewController传递到PersonViewController(表视图),但在表格中没有显示任何内容,所以我记录了数组计数并发现它为零,所以我使用以下代码进行了进一步检查:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
if (array == nil) {
NSLog(@"array is null");
}
else
{
NSLog(@"array count is %lu",(unsigned long)[array count]);
return [array count];
}
我收到了“数组为空”的消息,请帮我解决这个问题。
prepareForSegue
中不需要实例化(alloc
/init
)目标视图控制器。它已经为您实例化了。Andrew,如果您将其发布为答案,我会点赞的! - Rob