我想从一个VC传递一个int到另一个。我正在这样做。传递一个Int从一个ViewController到另一个使用segue
在我的VC1中,当我调用prepareForSegue方法时,我在做一个segue showDetail
。它看起来像这样。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = (NSIndexPath *)sender;
News *news = [arrNews objectAtIndex:indexPath.row];
NSLog(@"news id is %@",news.new_id);
if ([segue.identifier isEqualToString:@"showDetail"]) {
[segue.destinationViewController setNewsId:(int)news.new_id];
}
}
在日志中我得到了正确的数字。现在在我的VC2中,我已经声明了这样一个int。
@property (nonatomic) int newsId;
而我的setMethod看起来像这样。
-(void)setNewsId:(int)newsId{
NSLog(@"news id is %d",newsId);
self.newsId = newsId;
}
当我执行时,我进入一个循环与所有大数字。有人可以帮我解决这个问题吗?
news.new_id的类型是什么?为什么你需要在-setNewsId:call中将其转换为int? – Gereon 2013-03-19 08:03:23
看到我的回答.... – 2013-03-19 08:13:33