2012-02-03 3 views
0

私はテキストビューのオートコンプリートテキストで作業していますので、最初はUITextViewduplicateTextView)はウォーターマークテキストのようなバックグラウンドテキストで、2番目はUITextViewcustomTextView)です。ユーザーがtextviewに複数行テキストを入力すると、customTextViewは自動的にスクロールしますが、duplicateTextViewはスクロールしません。だから、複数行のテキストが入力されている間にduplicateTextViewをスクロールするにはどうすればよいですか? 2つのUITextViewをiPhoneで一緒にマージすることは可能ですか? @KAREEM MAHAMMEDを説明しようとしたとして、あなたはあなたが投稿したコードの最後の行にあなたのduplicateTextViewにcustomTextViewを追加している、iPhoneで2つのUITextViewをマージするには?

duplicateTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, 320, 100)]; 
duplicateTextView.delegate = self; 
duplicateTextView.scrollEnabled = YES; 
duplicateTextView.font = [UIFont fontWithName:@"Helvetica" size:14]; 
duplicateTextView.textColor = [UIColor lightGrayColor]; 
[self.view addSubview:duplicateTextView]; 

customTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; 
customTextView.layer.borderWidth = 2.0; 
customTextView.delegate = self; 
customTextView.backgroundColor = [UIColor clearColor]; 
customTextView.layer.borderColor = [UIColor blackColor].CGColor; 
customTextView.font = [UIFont fontWithName:@"Helvetica" size:14]; 
customTextView.textColor = [UIColor blackColor]; 
[duplicateTextView addSubview:customTextView]; 
+1

あなたがそれにcustomTextViewを追加したのでduplicateTextView –

+0

あなたの返信のためにありがとう –

+0

これはcustomTextViewではなく、ちょうどUITextView –

答えて

0

は、ここで私は、ソースコードを試してみました。おそらくあなたは次の代わりに次のことをすることになりました。 [self.view addSubview:customTextView];

おそらく私はあなたの質問に誤解しました。あなたが作業の例を見ることができるので、私はここにいくつかのコードを追加している:

.hファイル:

#import <UIKit/UIKit.h> 

@class TestViewController; 

@interface TestAppDelegate : 
NSObject <UIApplicationDelegate, UIScrollViewDelegate, UITextViewDelegate> 
{ 
    UIWindow *window; 
    TestViewController *viewController; 

    UITextView *customTextView; 
    UITextView *duplicateTextView; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet TestViewController *viewController; 

-(void)syncScroll; 

@end 

と.mファイル:あなたはと対話カントabooveコードを使用して

#import "TestAppDelegate.h" 
#import "TestViewController.h" 

@implementation TestAppDelegate 

@synthesize window; 
@synthesize viewController; 


#pragma mark - 
#pragma mark Application lifecycle 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // custom 
    customTextView = [[[UITextView alloc] initWithFrame:CGRectMake(10.0, 10.0, 80.0, 125.0)] autorelease]; 
    customTextView.backgroundColor = [UIColor whiteColor]; 
    [viewController.view addSubview:customTextView]; 

    // duplicate 
    duplicateTextView = [[[UITextView alloc] initWithFrame:CGRectMake(170.0, 10.0, 80.0, 125.0)] autorelease]; 
    duplicateTextView.backgroundColor = [UIColor whiteColor]; 
    duplicateTextView.editable = NO; 
    duplicateTextView.scrollEnabled = NO; 
    [viewController.view addSubview:duplicateTextView]; 

    // whenever text is entered into the customTextView then sync scrolling 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(syncScroll) 
               name:UITextViewTextDidChangeNotification 
               object:customTextView]; 
    customTextView.delegate = self; 

    // Add the view controller's view to the window and display. 
    [self.window addSubview:viewController.view]; 
    [self.window makeKeyAndVisible]; 

    // have keyboard show up in customTextView 
    [customTextView becomeFirstResponder]; 

    return YES; 
} 

#pragma mark - 
#pragma mark Memory management 

- (void)dealloc { 
    [viewController release]; 
    [window release]; 
    [super dealloc]; 
} 

#pragma mark - 
#pragma mark Other Methods 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    [self syncScroll]; 
} 

-(void)syncScroll { 
    duplicateTextView.text = customTextView.text; 
    [duplicateTextView setContentOffset:customTextView.contentOffset]; 
} 


@end 
+0

Mr.ragamufin私はあなたの提案に疲れました。しかし、それでも上記のcustomTextViewはスクロールし、duplicateTextViewはそこにとどまります。ありがとう。 –

+0

まず、両方のテキストビューが同じ位置にありません。複製は0,0にあり、カスタムは0,0にあります。第二に、ユーザーがカスタムテキストに入力するときに、同じテキストを重複するテキストに配置する必要があるため、自動的にそこに到達するとは思わない。ユーザーは、一度に1つのボックスに入力することしかできないと思います。ユーザーが入力したものを複製に貼り付けるコードを追加してみてください。理にかなっている? – ragamufin

+0

明確にするために私の答えにいくつかのコードを追加しました。もう一度見てください。 – ragamufin

関連する問題