Iphone 详细视图上文本视图对象的滚动位置不为';返回时不能重置

Iphone 详细视图上文本视图对象的滚动位置不为';返回时不能重置,iphone,objective-c,cocoa-touch,interface-builder,Iphone,Objective C,Cocoa Touch,Interface Builder,我在主视图中有信息,该主视图使用UITableView对象和在我将用户选择推送到它之后出现的详细视图反转器 我的挑战是在UITextView对象中滚动,而不是返回到细节视图上滚动区域的顶部 用户从主视图控制器中的列表中选择详图对象,然后在详图视图控制器中将其显示。然后,她在该视图上的UITextView对象DogScrollingFoTextView中滚动,向下移动得更远,以便不再显示上面的行。然后,她返回主视图控制器,并选择不同的行。返回细节视图后,新对象的UITextView对象(DogSc

我在主视图中有信息,该主视图使用UITableView对象和在我将用户选择推送到它之后出现的详细视图反转器

我的挑战是在UITextView对象中滚动,而不是返回到细节视图上滚动区域的顶部

用户从主视图控制器中的列表中选择详图对象,然后在详图视图控制器中将其显示。然后,她在该视图上的UITextView对象DogScrollingFoTextView中滚动,向下移动得更远,以便不再显示上面的行。然后,她返回主视图控制器,并选择不同的行。返回细节视图后,新对象的UITextView对象(DogScrollingFoTextView)仍位于上一个视图留下的位置

在detailViewController中传递到此UITextView的对象与主视图控制器中的类似

  self.detailViewController.dogScrollingInfo = dog.whatMakesDogSpecial;
在原始类定义中,该属性的声明如下

 @property (strong, nonatomic) NSString *dogScrollingInfo;
 @property (weak, nonatomic) IBOutlet UITextView *dogScrollingInfoTextView;
 self.dogScrollingInfoTextView.text = [self.dogScrollingInfo description];
@属性(强,非原子)NSString*whatMakesDogSpecial

用于在detailView控制器类中传输到视图的对象声明如下

 @property (strong, nonatomic) NSString *dogScrollingInfo;
 @property (weak, nonatomic) IBOutlet UITextView *dogScrollingInfoTextView;
 self.dogScrollingInfoTextView.text = [self.dogScrollingInfo description];
在detailViewController实现中,传输如下所示

 @property (strong, nonatomic) NSString *dogScrollingInfo;
 @property (weak, nonatomic) IBOutlet UITextView *dogScrollingInfoTextView;
 self.dogScrollingInfoTextView.text = [self.dogScrollingInfo description];
我不确定是否应该附加屏幕截图? 我应该输入其他代码吗?(我在下面列出了两个方法,每个视图控制器类一个)

我在UITextView类或UIView类中找不到任何与滚动相关的特定内容,这告诉我必须以编程方式执行某些操作。这似乎与InterfaceBuilder有关。我用的不是xib的故事板。但是我在不同的检查员中找不到任何改变这种行为的选择

我在详细视图控制器类中使用的configureView可能不是用于此目的的正确方法吗?我想我在Xcode Master Detail项目模板中找到了一个使用configureView方法的示例,尽管我是从单个视图项目模板构建应用程序的。如果没有,我怎么知道该用什么方法呢

我试图学习使用苹果的文档来解决这样的挑战,但我发现很难驾驭它。因此,关于如何更好地使用文档的建议非常受欢迎

。。。。主视图控制器类中的代码剪切

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

    if (!self.detailViewController) {
        self.detailViewController = [[HardlyWorkingDogsDetailViewController alloc]
                                     initWithNibName:@"HardlyWorkingDogsDetailViewController"
                                     bundle:nil ];

    }
    NSLog(@"The user selected dog @array position %d", indexPath.row);

    Dog *dog = self.sortedDogDictionaryArray[indexPath.row];


    self.detailViewController.dogName= dog.dogName;

    self.detailViewController.dogLicense = dog.licenseString;

    self.detailViewController.dogScrollingInfo = dog.whatMakesDogSpecial;

    self.detailViewController.dogPhoto = dog.dogPhoto;


    [self.navigationController pushViewController:self.detailViewController animated:YES];


  }
-(void)configureView {
    //NSLog(@"ConfigureView # 1 in detail vu");
    if (self.dogLicense) {

        self.dogLicenseUILabel.text = [self.dogLicense description];
        self.dogNameUIText.text = [self.dogName description];


        self.dogScrollingInfoTextView.text = [self.dogScrollingInfo description];

        self.dogPhotoUIImage.image = self.dogPhoto;


    }
}
。。。。“详细视图控制器”类中的代码剪切

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

    if (!self.detailViewController) {
        self.detailViewController = [[HardlyWorkingDogsDetailViewController alloc]
                                     initWithNibName:@"HardlyWorkingDogsDetailViewController"
                                     bundle:nil ];

    }
    NSLog(@"The user selected dog @array position %d", indexPath.row);

    Dog *dog = self.sortedDogDictionaryArray[indexPath.row];


    self.detailViewController.dogName= dog.dogName;

    self.detailViewController.dogLicense = dog.licenseString;

    self.detailViewController.dogScrollingInfo = dog.whatMakesDogSpecial;

    self.detailViewController.dogPhoto = dog.dogPhoto;


    [self.navigationController pushViewController:self.detailViewController animated:YES];


  }
-(void)configureView {
    //NSLog(@"ConfigureView # 1 in detail vu");
    if (self.dogLicense) {

        self.dogLicenseUILabel.text = [self.dogLicense description];
        self.dogNameUIText.text = [self.dogName description];


        self.dogScrollingInfoTextView.text = [self.dogScrollingInfo description];

        self.dogPhotoUIImage.image = self.dogPhoto;


    }
}
多谢各位
劳雷尔

因为您正在重用一个
硬工作狗DetailViewController
,所以这种行为是有意义的。如果
hardlyworkingdogsdeailviewcontroller
足够轻,就不需要重用它。只需每次重新试用即可解决您的问题:

self.detailViewController = [[HardlyWorkingDogsDetailViewController alloc] initWithNibName:@"HardlyWorkingDogsDetailViewController" bundle:nil ];

Dog *dog = self.sortedDogDictionaryArray[indexPath.row];

self.detailViewController.dogName= dog.dogName;
self.detailViewController.dogLicense = dog.licenseString;
self.detailViewController.dogScrollingInfo = dog.whatMakesDogSpecial;
self.detailViewController.dogPhoto = dog.dogPhoto;

[self.navigationController pushViewController:self.detailViewController animated:YES];
虽然没有看到您的其他逻辑,但如果您的任何代码依赖于只创建一次的
self.detailViewController
(例如,在其他地方保留对它的引用),我不能说这不会引入其他错误。如果是这种情况,或者您只是不想更改MasterViewController代码,您可以简单地将以下内容放入
硬加工狗DetailViewController

-(void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
     [self.dogScrollingInfoTextView setContentOffset:CGPointMake(0, 0) animated:NO];
}
这使得每次视图即将出现在屏幕上时,滚动视图都会回到顶部。(
viewDidLoad
视图将出现:
视图将消失:
视图将消失:
ViewDid消失:
UIViewController
生命周期的一部分,非常有用。您应该仔细阅读)


另一方面,
UITextView
是使用
UIScrollView
实现的,因此
UIScrollView
具有的任何滚动方法,
UITextView
也可以

因为您正在重用一个
硬工作狗DetailViewController
,所以这种行为是有意义的。如果
hardlyworkingdogsdeailviewcontroller
足够轻,就不需要重用它。只需每次重新试用即可解决您的问题:

self.detailViewController = [[HardlyWorkingDogsDetailViewController alloc] initWithNibName:@"HardlyWorkingDogsDetailViewController" bundle:nil ];

Dog *dog = self.sortedDogDictionaryArray[indexPath.row];

self.detailViewController.dogName= dog.dogName;
self.detailViewController.dogLicense = dog.licenseString;
self.detailViewController.dogScrollingInfo = dog.whatMakesDogSpecial;
self.detailViewController.dogPhoto = dog.dogPhoto;

[self.navigationController pushViewController:self.detailViewController animated:YES];
虽然没有看到您的其他逻辑,但如果您的任何代码依赖于只创建一次的
self.detailViewController
(例如,在其他地方保留对它的引用),我不能说这不会引入其他错误。如果是这种情况,或者您只是不想更改MasterViewController代码,您可以简单地将以下内容放入
硬加工狗DetailViewController

-(void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
     [self.dogScrollingInfoTextView setContentOffset:CGPointMake(0, 0) animated:NO];
}
这使得每次视图即将出现在屏幕上时,滚动视图都会回到顶部。(
viewDidLoad
视图将出现:
视图将消失:
视图将消失:
ViewDid消失:
UIViewController
生命周期的一部分,非常有用。您应该仔细阅读)


另一方面,
UITextView
是使用
UIScrollView
实现的,因此
UIScrollView
具有的任何滚动方法,
UITextView
也可以

谢谢大家!!这绝对有效。我取出if(!self.detailViewController){(和acompanying}它似乎工作得很好。我不认为其他任何事情取决于正在实例化的detailViewController,但我真的很感谢你的其他建议,因为它帮助我更好地思考和理解。你解释得非常好。谢谢!这绝对有效。我拿出了if(!self.detailViewController){(和公司}它似乎工作得很好。我不认为其他任何事情取决于正在实例化的detailViewController,但我真的很感谢你的其他建议,因为它帮助我更好地思考和理解。你解释得非常好。我看到codeinOrange提出了一些建议,我认为这些建议与我插入的方式有关ed在我的问题中删掉了代码。我正在努力学习更好地编写代码,所以我