Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 粘贴文本会产生额外的空间_Ios_Objective C - Fatal编程技术网

Ios 粘贴文本会产生额外的空间

Ios 粘贴文本会产生额外的空间,ios,objective-c,Ios,Objective C,在我的应用程序中,我需要将文本粘贴到UITextView中,并在UITableView中逐行查看它,但是我遇到了一个不寻常的问题,当我在应用程序中粘贴文本时,它会创建一个额外的未使用行,并将文本移到它下面的行。在图像中,您可以看到我在TextView的顶部输入文本,每次向下移动时,它都会创建一个空行 这是我的密码 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)

在我的应用程序中,我需要将文本粘贴到
UITextView
中,并在
UITableView
中逐行查看它,但是我遇到了一个不寻常的问题,当我在应用程序中粘贴文本时,它会创建一个额外的未使用行,并将文本移到它下面的行。在图像中,您可以看到我在TextView的顶部输入文本,每次向下移动时,它都会创建一个空行

这是我的密码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


cell.textLabel.text = [NSString stringWithFormat:@"%@",[listArray objectAtIndex:indexPath.row]];;


return cell;
}
 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


 return [listArray count];

}



-(void)textViewDidChange:(UITextView *)textView{

listArray=[[NSMutableArray alloc]initWithArray:[textView.text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]];

 [self.tableView reloadData];
}

这种情况并不是发生在我粘贴的所有内容上,而是发生在我需要输入到应用程序中的一段主要文本上

因此,您可以通过以下方式删除额外的空间

NSString *yourText = @" remove extra space  ";
NSString *finalText = [yourText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

因此,您可以通过以下方式删除额外的空间

NSString *yourText = @" remove extra space  ";
NSString *finalText = [yourText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

我只是得到一个未使用的变量警告作为最终文本。因为你没有在任何地方使用这个变量,即使我将其更改为textView,它仍然不会更改。这里是否缺少一些内容?给我你的文本视图的框架大小我只是得到一个未使用的变量警告作为最终文本。因为即使我更改它,你也没有在任何地方使用这个变量对于文本视图,它仍然没有改变。我这里缺少什么吗?给我你的文本视图的帧大小