为什么setText for textView添加textView底部的文本?

时间:2014-05-03 13:05:07

标签: ios xcode textview uitextview

我是目标c中的菜鸟,我创建了一个页面xib文件,该页面有一个textView为空。 我在这个页面拖动UITextView并连接到自助出口。 现在我想在其中添加任何类似“我是JANATAN”的文字。当我使用这个代码并运行我的模拟器时,我的模拟器显示我的textView但我看到我的句子是textView的最后一行! 为什么???这是我的形象:pic of simulator

这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    getTextPlaces = [self CreateTextViews];
    textField1 = [getTextPlaces objectAtIndex:0];
    [self.view addSubview:textField1];

    NSString *str = [_stack pop];
    textArray = [self readInformationFromDatabaseWithData:str];
    NSString *s1 = [[textArray objectAtIndex:0]objectForKey:@"Names"];
    textField1.text = [NSString stringWithFormat:@"%@",s1]; //this s1 value is I am janatan
}
- (NSMutableArray *)CreateTextViews{
    UITextView *tf = [[UITextView alloc] initWithFrame:CGRectMake(35, 70, 250, 50)];
    tf.backgroundColor = [UIColor purpleColor];
    tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    tf.autocorrectionType = UITextAutocorrectionTypeNo;
    tf.textAlignment = NSTextAlignmentRight;
    //tf.text=@"Hello World";

    //second one
    UITextView *tf1 = [[UITextView alloc] initWithFrame:CGRectMake(35, tf.frame.origin.y + 70, 250, 50)];
    tf1.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    tf1.backgroundColor=[UIColor whiteColor];
    tf1.autocorrectionType = UITextAutocorrectionTypeNo;
    tf1.textAlignment = NSTextAlignmentRight;

    //and so on adjust your view size according to your needs
    NSMutableArray *twoText = [[NSMutableArray alloc]init];

    [twoText addObject:tf];
    [twoText addObject:tf1];

    return twoText;

}

1 个答案:

答案 0 :(得分:0)

我的朋友要删除此项,您需要设置以下内容:

self.automaticallyAdjustsScrollViewInsets = NO;

在viewDidLoad方法中。