所以基本上我想在一个无序列表中添加一个UITextView.另一个UITextView我想添加一个有序列表.
我尝试使用这个代码,但它只是在用户第一次按下Enter键后给了我一个项目符号(不仅仅是那个),我甚至无法退格.
- (void)textViewDidChange:(UITextView *)textView
{
    if ([myTextField.text isEqualToString:@"\n"]) {
        NSString *bullet = @"\u2022";
        myTextField.text = [myTextField.text stringByAppendingString:bullet];
    }
}
Run Code Online (Sandbox Code Playgroud)
如果您只找到使用Swift执行它的方法,那么随意发布Swift版本的代码.
每当用户输入换行符时,我都会尝试在每行的开头添加一个数字.我希望数字按顺序排列(如在有序列表中),但是使用我当前的代码,如果用户最后没有添加新行,而是在中间添加行UITextView,则会继续从它在底部的位置开始计算 - 意味着NSUInteger我做了增量并且没有考虑到用户没有在最后创建新线.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        numbered ++;
        NSString *string = [NSString stringWithFormat:@"\n%lu ", (unsigned long)numbered];
        [self insertXEveryNewLine:range :textView :string];
        return NO;
    }
    return YES;
}
- (BOOL)insertXEveryNewLine:(NSRange)place :(UITextView *)View :(NSString *)something
{
    NSRange cursor = NSMakeRange(place.location + 3, 0);
    NSMutableString *mutableT = [NSMutableString stringWithString:View.text];
    [mutableT insertString:something atIndex:place.location];
    [View setText:mutableT];
    return NO;
}
Run Code Online (Sandbox Code Playgroud)
我刚发布的代码添加了一个编号列表,每个新行增加1.现在,如果您尝试在中间添加新行,而不是在最后,它将从最后一个行号增加1,它不会从前一行号增加.例如,如果用户添加6行UITextView,则用户转到第3行并添加新行,它将在第3行之后显示#7,因为每次用户创建新行时numbered都会增加1.
编辑

当用户在第1行之后添加新行时,我希望所有行都更新.希望这更清楚.
我设置了以下方法:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
Run Code Online (Sandbox Code Playgroud)
它工作正常并被调用,但它从不包含多个位置。我试图在手机移动时获取新旧位置之间的距离。我错过了什么吗?location 数组中永远不会有两个项目。
我用UILongPressGestureRecognizer我的UICollectionView.现在,当我在一段时间(例如1秒)后将手指放在CollectionView项目上时,我希望我UILongPressGestureRecognizer结束并执行某个代码:
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
- (void)viewDidLoad {
  [super viewDidLoad];
  Public = [[PublicMethods alloc]init];
  self.view.backgroundColor = [UIColor whiteColor];
  [self.view addSubview:self.collect];
  UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
  lpgr.minimumPressDuration = 3; //seconds
  lpgr.delaysTouchesBegan = YES;
  lpgr.delegate = self;
  [self.collect addGestureRecognizer:lpgr];
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
  if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
    return;
  }
  CGPoint p = [gestureRecognizer locationInView:self.collect];
  NSIndexPath *indexPath = [self.collect indexPathForItemAtPoint:p];
  if (indexPath == nil){
    NSLog(@"couldn't find index path");
  } else {
    // get …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Swift为iPhone创建一个单词jumbler游戏.我对编程和Swift比较陌生,但以前用Python创建过这个游戏.
这是我的伪代码:
//select RANDOM WORD from array
//determine the number of characters in the RANDOMLY SELECTED WORD
//randomly select a NUMBER within the boundries of the number of characters (i.e. if the word is "apple," select a number between 0 and 4)
//select the CHARACTER that corresponds to the randomly selected NUMBER
//add the CHARACTER to a new string (JUMBLE)
//remove the CHARCATER from the RANDOMLY SELECTED WORD
//Repeat until the RANDOM WORD is empty
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
导入UIKit
//this is my …Run Code Online (Sandbox Code Playgroud) 我想将UIButton背景颜色从黑色更改为白色.但我想在动画中改变它.例如......黑色>灰色>白色.在iPhone SDK中有没有简单的方法?谢谢.
我在Objective-C中看到了这个问题,但我不知道如何转换为swift.
我的应用程序从Facebook接收用户的公共信息,我需要将语言环境转换为国家/地区名称.
FBRequestConnection.startForMeWithCompletionHandler({
            connection, result, error in    
            user["locale"] = result["locale"]
            user["email"] = result["email"]
            user.save()
            println(result.locale)
        })
Run Code Online (Sandbox Code Playgroud)
例如,对于法国用户,代码将"Optional(fr_FR)"发送到日志.但是我需要它才能发送国家名称.根据localeplanet.com,显示名称"fr_FR"是"French(France)".因此在日志中我想要的只是"法国".
这个if/else语句占据了我班级的很大一部分,坦白说它很烦人.有什么办法可以让这个更小更少的代码吗?这只是我实际代码的一个例子,但是如果有人可以帮我减小尺寸,我可以将它应用到我的实际代码中.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
    if ([self.currentSearchStr length] == 0) {
        phoneViewController = [[viewController alloc] initWithNibName:@"viewController"
                                                               bundle:nil
                                                                 list:self.list
                                                                index:indexPath.row
                                                                title:self.title];
    } else {
        phoneViewController = [[viewController1 alloc] initWithNibName:@"viewController1"
                                                                bundle:nil
                                                                  list:self.list1
                                                                 index:indexPath.row
                                                                 title:self.title];
    }
} else {
    if ([self.currentSearchStr length] == 0) {
        padViewController = [viewController alloc] initWithNibName:@"viewController"
                                                            bundle:nil
                                                              list:self.list
                                                             index:appDelegate.mSelectedRow
                                                             title:self.title];
    } else {
        padViewController = [[viewController1 alloc] initWithNibName:@"viewController1"
                                                              bundle:nil
                                                                list:self.list1
                                                               index:appDelegate.mSelectedRow
                                                               title:self.title];
    }
Run Code Online (Sandbox Code Playgroud) 我从GitHub下载了一个开放源代码Xcode项目,但是将Mac更新到Catalina后,无法使用Xcode ver 10或ver 11 beta打开它。我做一个新项目没有任何问题。我已经重新启动了Mac几次,但是没有任何变化。
我想要一些建议:(
在故事板中,我有一个标签和许多其他对象UIScrollView.(UIScrollView在视图中).
我想在标签滚过它时将导航栏的标题设置为标签的标题.
我试过这段代码,但它不起作用:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if(self.lbl.frame.origin.x==60) {
        self.navigationController!.navigationBar.topItem!.title = lbl.text
    }
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?我是Swift的新手.