[英]Convert NSArray to NSstring in IOS
i have a NSMutableArray called delegate.allSelectedVerseEnglish from application delegate, it have some values, i am able to get the array count and i can show it correctly in UITableView. 我有一个NSMutableArray,它来自应用程序委托,它称为一些值,我可以获取数组计数,并且可以在UITableView中正确显示它。 But now i want to display it in a textview. 但是现在我想在textview中显示它。 My UITableView code is like this 我的UITableView代码是这样的
- (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];
}
}
It shows correct values in the cell, but i just need to show this delegate.allSelectedVerseEnglish array in a textview, like textview.text = delegate.allSelectedVerseEnglish;
它在单元格中显示了正确的值,但是我只需要在textview中显示这个委托。allSelectedVerseEnglish数组,例如textview.text = delegate.allSelectedVerseEnglish;
. 。 How it can be done? 怎么做?
Thanks in advance. 提前致谢。
Depends on how you want the text to be formatted. 取决于您要如何格式化文本。
For logging purposes, I'd use [delegate.allSelectedVerseEnglish description];
为了进行记录,我将使用[delegate.allSelectedVerseEnglish description];
while for showing it to the user something like [delegate.allSelectedVerseEnglish componentsJoinedByString:@"\\n"];
同时向用户显示类似[delegate.allSelectedVerseEnglish componentsJoinedByString:@"\\n"];
might be suitable. 可能合适。
You can use like this - 您可以这样使用-
NSString *stringToShow = nil;
for (NSString *stringObj in delegate.allSelectedVerseEnglish) {
stringToShow = [stringToShow stringByAppendingString: [NSString stringWithFormat:@"%@",stringObj]];
}
cell.textLabel.text = stringToShow;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.