Ios indexPath.row始终返回0
我注意到关于这个问题有几个线程,但每个线程都取决于代码,所以我决定用我的代码片段开始我自己的线程。代码如下:Ios indexPath.row始终返回0,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我注意到关于这个问题有几个线程,但每个线程都取决于代码,所以我决定用我的代码片段开始我自己的线程。代码如下: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [articles count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [articles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ArticleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Article *article = [articles objectAtIndex:indexPath.row];
cell.textLabel.text = article.articleTitle;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showArticleDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ArticleDetailViewController *destViewController = segue.destinationViewController;
destViewController.article = [articles objectAtIndex:indexPath.row];
}
}
有什么帮助吗
谢谢 在您的代码中
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [articles count];
}
aricles计数
为零或一。因此,我使用NSLog检查文章计数的值
Alloc
您的文章。如果其NSMutableArray
则alloc
如下所示
NSMutableArray *articles = [[NSMutableArray alloc] init];
设置@接口MyView:UIView
在.h文件中
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showLocationDetails"])
{
LocationDetailsViewController *vc = [segue destinationViewController];
indexPathSelected = [self.tableView indexPathForCell:sender].row;
vc.location = _locationsArray[indexPathSelected];
}
}
相应地设置segue方法。行数方法在哪里?它在哪里返回0?你们在屏幕上看到了什么结果?你想解决什么问题?@Fogmeister我已经用numberofrows方法更新了代码。那么什么是articles.count。plz应答nirvavtoo@NiravBhatt-嗯,有好几篇文章,无论您在哪篇文章上单击详细信息页面,都会显示第一篇文章的数据。我使用NSLog检查indexPath.row的值,它总是0。articles count返回正确的数字。我使用的是“articles=[[NSMutableArray alloc]init];”。.h文件中的代码是相同的。您发布的方法在.m文件和viewdidload中返回了许多错误。