Iphone 在IOS中将NSArray转换为NSstring
我有一个名为delegate.allSelectedVerseEnglish的NSMutableArray,它来自application delegate,它有一些值,我能够获得数组计数,并且可以在UITableView中正确显示它。但现在我想在文本视图中显示它。我的UITableView代码如下Iphone 在IOS中将NSArray转换为NSstring,iphone,ios,nsstring,nsarray,Iphone,Ios,Nsstring,Nsarray,我有一个名为delegate.allSelectedVerseEnglish的NSMutableArray,它来自application delegate,它有一些值,我能够获得数组计数,并且可以在UITableView中正确显示它。但现在我想在文本视图中显示它。我的UITableView代码如下 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize t
- (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.text=delegate.allSelectedVerseEnglish代码>。如何做到这一点
提前感谢。取决于您希望文本的格式。
出于日志记录的目的,我会使用[delegate.allSelectedVerseEnglish description]代码>用于向用户显示它,例如[delegate.allSelectedVerseEnglish componentsJoinedByString:@“\n”]代码>可能很合适。您可以这样使用-
NSString *stringToShow = nil;
for (NSString *stringObj in delegate.allSelectedVerseEnglish) {
stringToShow = [stringToShow stringByAppendingString: [NSString stringWithFormat:@"%@",stringObj]];
}
cell.textLabel.text = stringToShow;
感谢您的回复,因此我必须编写textview.text=[delegate.AllSelectedVerseenEnglish Components由字符串连接:@“\n”];是吗?让我们在聊天中继续讨论:为什么不使用stringObj
而不是[NSString stringWithFormat:@“%@”,stringObj]
?根据问题,数组是否始终包含字符串变量并不清楚?但如果我们确定,那么我们肯定可以使用此选项:)为什么使用(NSString*stringObj in.
then?@RIP我将NSString*stringToShow=nil;for(NSString*stringObj in DEGRASE.allSelectedVerseEnglish){stringToShow=[stringToShow stringByAppendingString:[NSSTRINGWITHFORMAT:@“%@”,stringObj]];}cell.textLabel.text=stringToShow;agin无结果..数组中包含文本