如何在不使用 fetchresultscontroller 的情况下使用 coredata 向下钻取表视图
我在第一个屏幕中有一个表格视图,我单击“添加”按钮,然后在那里添加详细信息(名字、姓氏和年龄)并保存。它已保存,让我进入父屏幕,当我单击附件指示器时,我想要进入相同的视图,并在这些文本字段中查看我所选行的详细信息。我使用 segue 的 n 传递对象,对象已传递,但我在文本字段中没有看到它,我得到一个带有空文本字段的屏幕。感谢显示下面的代码:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"AddNew"])
{
addNewController = segue.destinationViewController;
addNewController.delegate = self;
}
else if ([segue.identifier isEqualToString:@"ShowRow"])
{
NSIndexPath *pathChosen = self.tableView.indexPathForSelectedRow;
personObject = [self.personArray objectAtIndex:pathChosen.row];
NSLog(@"the row selected is %@",personObject);
self.addNewController = segue.destinationViewController;
self.addNewController.personObject = self.personObject;
self.addNewController.personObject = self.personObject;
self.personObject.firstName = addNewController.firstNametxt.text;
NSLog(@"the row selected is %@",addNewController.firstNametxt.text);
//its giving me a null value here for addnewcontroller.firstNametxt.text.
}
}
i have a table view in the first screen i click on the add button n go add details there (first name ,last name and age) and save. Its saved n gets me to the parent screen,den wen i click on the accessory indicator i want to go the same view n see those details of my selected row in those text fields. Im using segue's n passing the object, the object is passed but i dont see it in the textfields ,i get a the screen with empty textfields.thanks showing the code below:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"AddNew"])
{
addNewController = segue.destinationViewController;
addNewController.delegate = self;
}
else if ([segue.identifier isEqualToString:@"ShowRow"])
{
NSIndexPath *pathChosen = self.tableView.indexPathForSelectedRow;
personObject = [self.personArray objectAtIndex:pathChosen.row];
NSLog(@"the row selected is %@",personObject);
self.addNewController = segue.destinationViewController;
self.addNewController.personObject = self.personObject;
self.addNewController.personObject = self.personObject;
self.personObject.firstName = addNewController.firstNametxt.text;
NSLog(@"the row selected is %@",addNewController.firstNametxt.text);
//its giving me a null value here for addnewcontroller.firstNametxt.text.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你真的应该清理你的代码,伙计。有重复的行,一行紧挨着另一行。如果你想在不发疯的情况下成功编码,你就必须更加准确和专注。
你的赋值语句应该是相反的。我相信你自己可以发现一个小错误。
顺便说一句,如果这不起作用,可能是因为您的
addNewController
尚未创建其文本字段。最好在控制器本身中填充文本字段,最好在方法viewDidLoad
中。您定义为属性的personObject
将可用于此。You should really clean up your code, man. There are duplicated lines one just below the other. You will have to work with more accuracy and concentration if you want to code successfully without going crazy.
Your assignment statement should be the other way round. A trivial mistake that I am sure you could have caught yourself.
By the way, if this does not work it is because maybe your
addNewController
has not yet created its text fields. Better to do the filling of text fields in the controller it self, best in the methodviewDidLoad
. ThepersonObject
which you defined as a property would be available for that.