我正在尝试完成一件非常简单的事情。当我的集合视图中的唯一项被推送时,我尝试以编程方式推送到viewController。什么都没发生。我相信在我错综复杂的混乱中有不止一个问题。我对数组的基础知识的理解显然不是这样。如果我在下面的If语句中放入一个NSLog行,当我推入我的唯一项时,我什么也得不到。下面是我的didSelectItemAtIndexPath方法:
NSMutableArray *itemApp = [model.viewControllers objectAtIndex:indexPath.row];
if (itemApp == 0) {
NSLog (@"This does not appear")
TableViewController *ctc = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:ctc animated:YES];
}模型在viewDidLoad中定义:
model = [[SimpleModel alloc] init];.m实现中提到了SimpleModel:
@implementation smileController;
{
SimpleModel *model;
} viewControllers是SimpleModel类的属性,还有它的朋友应用程序:
@property (nonatomic, strong) NSMutableArray *apps;
@property (nonatomic, strong) NSMutableArray *viewControllers;下面是SimpleModel.m
- (id)init
{
if (self = [super init])
{
self.apps = [NSMutableArray arrayWithObjects:@"1", nil];
self.viewControllers = [NSMutableArray arrayWithCapacity:self.apps.count];
TableViewController *tvc = [[TableViewController alloc] init];
[self.viewControllers addObject:tvc];
}
return self;
}发布于 2013-03-20 04:46:38
在SimpleModel.m中,您使用单个TableViewController填充viewControllers数组。
鉴于此,当您发布的第一段代码应该更像这样时:
TableViewController *itemApp = [model.viewControllers objectAtIndex:indexPath.row];
if (itemApp) {
NSLog (@"This should appear")
[self.navigationController pushViewController:itemApp animated:YES];
}这假设您想要推送从model.viewControllers属性获得的视图控制器。
请注意,只有当model或model.viewControllers为nil时,model才能为model.viewControllers。
https://stackoverflow.com/questions/15509831
复制相似问题