2012-04-22 245 views
0

我有一个名为delegate.allSelectedVerseEnglish的应用程序委托的NSMutableArray,它有一些值,我能够获得数组数并且我可以在UITableView中正确显示它。但是现在我想在textview中显示它。我UITableView的代码是这样的将NSArray转换为IOS中的NSstring

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

     return [delegate.allSelectedVerseEnglish count]; 
} 


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

    static NSString *CellIdentifier = @"Cell"; 
    readCell *cell = (readCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"readCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 

     cell.label.text = [NSString stringWithFormat:@"%d",indexPath.row+1]; 
     cell.textLabel.text = [NSString stringWithFormat:@" %@",[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row]]; 
     cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:19.0]; 
    } 
} 

它在细胞中显示正确的价值观,但我只需要显示此delegate.allSelectedVerseEnglish阵列在一个TextView,像textview.text = delegate.allSelectedVerseEnglish;。如何做到这一点?

在此先感谢。

回答

5

取决于您希望如何格式化文本。
为了记录目的,我会使用[delegate.allSelectedVerseEnglish description];,同时向用户展示它可能是合适的,如[delegate.allSelectedVerseEnglish componentsJoinedByString:@"\n"];

+1

感谢您的答复,,所以我必须写textview.text = [delegate.allSelectedVerseEnglish componentsJoinedByString:@ “\ n”];对? – stackiphone 2012-04-22 07:58:03

+0

是的,这应该做的伎俩。 – 2012-04-22 08:00:48

+0

让我试试这个。谢谢 – stackiphone 2012-04-22 08:01:26

2

您可以使用这样的 -

NSString *stringToShow = nil; 
for (NSString *stringObj in delegate.allSelectedVerseEnglish) { 
    stringToShow = [stringToShow stringByAppendingString: [NSString stringWithFormat:@"%@",stringObj]]; 
} 
cell.textLabel.text = stringToShow; 
+3

为什么不'你可以使用'stringObj'而不是'[NSString stringWithFormat:@“%@”,stringObj]'? – 2012-04-22 08:00:14

+0

根据问题,它不清楚数组总是包含字符串变量?但是如果我们确定那么我们肯定可以使用这个:) – rishi 2012-04-22 08:03:36

+0

为什么你用'for(NSString * stringObj in ..' then? – 2012-04-22 08:04:17