2011-11-24 54 views
2

我使用下面的代码获取行的索引号。我想获得行的文本。请告诉我,需要进行哪些修改才能从每一行获取文本。Iphone tableview

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{ 

    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
    [self.navigationController pushViewController:detail animated:YES]; 

    detail.rowNum.text = [NSString stringWithFormat:@"Row: %d", (indexPath.row) ]; 
} 

thanx提前:)

回答

1

你可以得到所有的属性细胞是这样的:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{ 
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    detail.rowNum.text = [NSString stringWithFormat:@"Row: %d", (indexPath.row) ]; 
    detail.someLabel.text = cell.textLabel.text; 

    [self.navigationController pushViewController:detail animated:YES]; 
} 

这是你想要的吗?选定单元格的文字?

+0

thanx Condor!其实我是新来的ios,所以你会告诉我在上面的代码中添加此代码的位置? – AppDeveloper

+0

答复已更新。 –

+0

谢谢秃鹰!你是伟大的 – AppDeveloper

0
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{ 

    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
    [self.navigationController pushViewController:detail animated:YES]; 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    NSString *cellText = cell.textLabel.text; 
    detail.rowNum.text = cellText; 
} 

更新上面的代码。

+0

thanx是多数民众赞成在我正在寻找.... – AppDeveloper

+0

感谢“iamsult”你让我很容易...你能告诉我,如果有任何书,我可以轻松学习IOS编程。 ...我渴望学习 – AppDeveloper

+0

如果你有确切的答案,你应该upvote或接受它。现在来看这本书,iOS已经改变了很多。你最好从viewcontrollerpgforiphoneos指南开始,通过苹果,它会给你清晰的SDK概念,然后你可以根据需要阅读教程。对于初学者来说,这是有帮助的http://www.raywenderlich.com/tutorials – iamsult