2013-03-06 2 views
2

* iam iphone 개발 초심자입니다. uitextview에서 한 가지 문제가 있습니다 ... wat iam은 텍스트 뷰에서 uitextview의 선택된 문자열을 드래그하여 tabbarcontroller로 드래그하는 것이 가능합니다. . *이 코드가 되 잖아 지금 .... PLZ 나에게 도움까지 돌려주고텍스트 뷰에서 uitextview에서 선택한 문자열을 드래그하는 방법?

# 사용자가 텍스트 뷰 내부에 접촉

import <UIKit/UIKit.h> 
#import "TabViewController.h" 

@class TabBarViewController; 

@interface TabBarAppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate> 
{ 

    TabBarViewController *txtviewcontroller; 
    UITabBarController *tabbar; 
    NSArray *viewcontrollerarray; 

} 
@property(nonatomic,retain)NSArray *viewcontrollerarray; 
@property(nonatomic,strong)UITabBarController *tabbar; 
@property(nonatomic,retain)TabBarViewController *txtviewcontroller; 


@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) TabBarViewController *viewController; 

@end 
#import "TabBarAppDelegate.h" 

#import "TabViewController.h" 

@implementation TabBarAppDelegate 
@synthesize txtviewcontroller,tabbar,viewcontrollerarray; 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.window.backgroundColor=[UIColor whiteColor]; 
    self.tabbar=[[UITabBarController alloc]init]; 
    txtviewcontroller=[[TabBarViewController alloc]init]; 
    tabbar.delegate=self; 
    viewcontrollerarray=[[NSArray alloc]initWithObjects:txtviewcontroller, nil]; 
    self.tabbar.viewControllers=viewcontrollerarray; 


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[TabBarViewController alloc] initWithNibName:@"TabBarViewController_iPhone" bundle:nil]; 
    } else { 
     self.viewController = [[TabBarViewController alloc] initWithNibName:@"TabBarViewController_iPad" bundle:nil]; 
    } 
    self.window.rootViewController = self.tabbar; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
#import <UIKit/UIKit.h> 

@interface TabBarViewController : UIViewController 
{ 
    UITextView *textview; 
} 
@property(nonatomic,retain)UITextView *textview; 

@end 


#import "TabViewController.h" 
#import "TabBarAppDelegate.h" 
#include <QuartzCore/CoreAnimation.h> 

@interface TabBarViewController() 

@end 

@implementation TabBarViewController 
@synthesize textview; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [email protected]"firstname"; 
    CGRect textViewFrame = CGRectMake(20.0f, 20.0f, 280.0f, 124.0f); 

    textview = [[UITextView alloc] initWithFrame:textViewFrame]; 
    textview.backgroundColor=[UIColor clearColor]; 
    textview.textColor=[UIColor blackColor]; 
    textview.editable=NO; 
    NSString *filePath=[[NSBundle mainBundle]pathForResource:@"satyadetails" ofType:@"txt"]; 
    NSString *contentString=[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; 
    textview.text=contentString; 
    textview.layer.borderWidth = 3.0f; 

    textview.layer.borderColor = [[UIColor grayColor] CGColor]; 
    textview.returnKeyType = UIReturnKeyDone; 
    [self.view addSubview:textview]; 
enter code here 


} 

답변

1

1 단계 가져 오기 이벤트 (당신은 얻을 수 UITextView 년대에 의해 대표자 (startEditing 대의원)

2 단계 : ur에 UILabel을 추가합니다. 사용자가 텍스트 뷰에서 터치하고 텍스트 뷰에서 텍스트를 제공하고 배경색으로 선명한 색상을주는 위치를 제공합니다. (텍스트 뷰의 대표자 내에서이 작업을 수행하십시오.)

3 단계 터치하면 내부에서 터치로 이동하여 ur 레이블의 위치를 ​​동적으로 변경합니다.

4 단계. 사용자가 터치를 옮길 때까지 텍스트 뷰 위임자가 호출됩니다. if(textview==droppingtextview) 다음에 draggingtextview.text=label.text을 입력하십시오. superview에서 레이블을 제거하십시오.

+0

유용한 제안을 주셔서 감사합니다. 제가 제안한 방식대로 작동합니다 .. –

관련 문제