Iphone 将数据从委托传递到UIViewController
我有一个Iphone 将数据从委托传递到UIViewController,iphone,objective-c,cocoa-touch,uitableview,nsarray,Iphone,Objective C,Cocoa Touch,Uitableview,Nsarray,我有一个视图控制器: @interface SubmitCampaignViewController:UIViewController<SocialPagesViewControllerDelegate> 我想将数据从submitcompaignviewcontroller传递到SocialPagesViewController 所以我这样写: @protocol SocialPagesViewControllerDelegate; @interface SocialPagesVi
视图控制器
:
@interface SubmitCampaignViewController:UIViewController<SocialPagesViewControllerDelegate>
我想将数据从submitcompaignviewcontroller
传递到SocialPagesViewController
所以我这样写:
@protocol SocialPagesViewControllerDelegate;
@interface SocialPagesViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, weak) id<SocialPagesViewControllerDelegate> delegate;
@property (nonatomic, weak) NSArray *pages;
@end
SocialPagesViewController *socialViewController = [storyboard instantiateViewControllerWithIdentifier:@"socialPages"];
socialViewController.delegate = self;
socialViewController.pages = objects;
[self presentViewController:socialViewController animated:NO completion:NULL];
但是,尽管对象不是0,self.pages.count却是0
SocialPagesViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
DLog(@"%d",self.pages.count);
return self.pages.count;
}
如何将对象
NSArray
从submitCompaignViewController
传递到SocialPagesViewController
?尝试将数组的引用设置为强引用。
@property(非原子,强)NSArray*页
我建议将页面的setter设置为@属性(非原子,复制)NSArray*页面
因为您需要将相同的数组对象
放入页面
在演示socialViewController时
socialViewController.pages = [objects copy];
这是正确的答案。但如果我使用强光和弧光,会不会伤害我?当我关闭social的viewcontroller时,它是否知道释放对象?使用copy vs strong是否更好?如果使用strong,它将从原始指针值复制指针值。retain还将引用计数增加1。但在复制的情况下,它会复制指针引用的数据,并将其分配给复制的实例变量。在您的情况下,最好是复制更好。因此,在这种情况下使用strong不是更好吗?如果您需要对象的当前值,则使用strong没有什么大的缺点,您不希望该值反映对象的其他所有者所做的任何更改。