2016-03-22 13 views
0

私のアプリケーションでは、テキストをUITextViewに貼り付け、UITableViewの行ごとに表示する必要がありますが、アプリケーション内にテキストを貼り付けたときに余分な未使用行の下の行に移動します。 For example。イメージでは、TextViewの一番上のテキストを入力して、それが下に移動するたびに空の行を作成することがわかります。テキストを貼り付けて余分なスペースを作成する

Heres my code。

-(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]; 
} 

これは私が貼りすべてのために発生しませんが、私はアプリケーションに入力する必要があるテキストの、基本的には、1つのメイン部分のために起こるん。

答えて

2

ので、あなたは、次のよう

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

私は、最終的なテキストのために使用されていない変数の警告を取得することにより、余分なスペースを削除することができます。 – vype

+0

あなたがこの変数をどこでも使用しなかったので、 – Jamil

+0

私はtextViewに変更してもそれは変わらない。 – vype