iphone - 如何将uitextview中的选定字符串从textview中拖出。?
<p><p>*<em>我是 iphone 开发的初学者。
我在 uitextview 中遇到了一个问题...我正在尝试做的是将 uitextview 中选定的字符串从 textview 中拖出...并将其拖到 tabbarcontroller 是否有可能请帮我解决这个问题...。 </em>*这是我到目前为止返回的代码......请帮助我</p>
<p>#</p>
<pre><code>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 = [ initWithFrame:[ bounds]];
// Override point for customization after application launch.
self.window.backgroundColor=;
self.tabbar=[init];
txtviewcontroller=[init];
tabbar.delegate=self;
viewcontrollerarray=[initWithObjects:txtviewcontroller, nil];
self.tabbar.viewControllers=viewcontrollerarray;
if ([ userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [ initWithNibName:@"TabBarViewController_iPhone" bundle:nil];
} else {
self.viewController = [ initWithNibName:@"TabBarViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.tabbar;
;
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
{
;
// Do any additional setup after loading the view, typically from a nib.
self.title=@"firstname";
CGRect textViewFrame = CGRectMake(20.0f, 20.0f, 280.0f, 124.0f);
textview = [ initWithFrame:textViewFrame];
textview.backgroundColor=;
textview.textColor=;
textview.editable=NO;
NSString *filePath=[pathForResource:@"satyadetails" ofType:@"txt"];
NSString *contentString=;
textview.text=contentString;
textview.layer.borderWidth = 3.0f;
textview.layer.borderColor = [ CGColor];
textview.returnKeyType = UIReturnKeyDone;
;
enter code here
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>步骤 1. 用户在 textview 内部触摸时获取事件(您可以通过 <code>UITextView</code> 的委托(delegate)(<code>startEditing</code> 委托(delegate))获取)</p>
<p>步骤 2. 在你的 View 上添加一个 <code>UILabel</code>,给出用户在 textview 中触摸的位置,并将文本作为 textview 的文本,并将清晰的颜色作为背景色。 (在 textview 的委托(delegate)内执行此操作)</p>
<p>Step 3. Inside touches move of ur view会根据touches动态改变你标签的位置。</p>
<p>第 4 步。当用户移动其触摸直到删除 textview 委托(delegate)将被调用检查那里 <code>if(textview==droppingtextview)</code> 然后放 <code>draggingtextview.text=label.text</code> .并从 superview 中删除标签。</p></p>
<p style="font-size: 20px;">关于iphone - 如何将uitextview中的选定字符串从textview中拖出。?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15247727/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15247727/
</a>
</p>
页:
[1]