首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didSelectItemAtIndexPath pushViewController

didSelectItemAtIndexPath pushViewController
EN

Stack Overflow用户
提问于 2013-03-20 04:31:08
回答 1查看 729关注 0票数 0

我正在尝试完成一件非常简单的事情。当我的集合视图中的唯一项被推送时,我尝试以编程方式推送到viewController。什么都没发生。我相信在我错综复杂的混乱中有不止一个问题。我对数组的基础知识的理解显然不是这样。如果我在下面的If语句中放入一个NSLog行,当我推入我的唯一项时,我什么也得不到。下面是我的didSelectItemAtIndexPath方法:

代码语言:javascript
复制
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中定义:

代码语言:javascript
复制
    model = [[SimpleModel alloc] init];

.m实现中提到了SimpleModel:

代码语言:javascript
复制
@implementation smileController;

{
SimpleModel *model;
}    

viewControllers是SimpleModel类的属性,还有它的朋友应用程序:

代码语言:javascript
复制
@property (nonatomic, strong) NSMutableArray *apps;
@property (nonatomic, strong) NSMutableArray *viewControllers;

下面是SimpleModel.m

代码语言:javascript
复制
 - (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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-20 04:46:38

SimpleModel.m中,您使用单个TableViewController填充viewControllers数组。

鉴于此,当您发布的第一段代码应该更像这样时:

代码语言:javascript
复制
TableViewController *itemApp = [model.viewControllers objectAtIndex:indexPath.row];

if (itemApp) {
    NSLog (@"This should appear")
    [self.navigationController pushViewController:itemApp animated:YES];
}

这假设您想要推送从model.viewControllers属性获得的视图控制器。

请注意,只有当modelmodel.viewControllersnil时,model才能为model.viewControllers

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15509831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档