在iphone的textview中显示数组值
我有一个名为bookmark的数组,它包含值,我在tableview单元格中显示它,我知道如何在tablecell中显示它。但我希望相同的数组在textview中显示它。这是我的tableview代码在iphone的textview中显示数组值,iphone,objective-c,ios,Iphone,Objective C,Ios,我有一个名为bookmark的数组,它包含值,我在tableview单元格中显示它,我知道如何在tablecell中显示它。但我希望相同的数组在textview中显示它。这是我的tableview代码 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //自定义表视图中的行数 - (NSInteger)tableView:(UITableView *)tableView nu
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//自定义表视图中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [bookmarks count];
}
// Customize the appearance of table view cells.
- (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] autorelease];
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bgCELL3@2X-1"]];
[cell setBackgroundView:img];
[img release];
}
cell.textLabel.font =[UIFont fontWithName:@"Georgia" size:15];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@:%@ ",[[bookmarks objectAtIndex:indexPath.row] objectForKey:@"book"],[[bookmarks objectAtIndex:indexPath.row] objectForKey:@"chapter"],[[bookmarks objectAtIndex:indexPath.row] objectForKey:@"verse"],[[bookmarks objectAtIndex:indexPath.row] objectForKey:@"text"]];
// Set up the cell...
return cell;
}
我想用mytextview.text=?替换cell.textlabel.text。请帮助我完成此操作。
提前感谢。您可以使用与
UILabel的文本相同的方式设置UITextView的文本
mytextview.text = [[bookmarks objectAtIndex:0] objectForKey:@"text"];
或者,例如,在循环中:
NSString *resultStr = @"";
for (id bookmark in bookmarks)
{
resultStr = [NSString stringWithFormat:@"%@. %@", resultStr, [bookmark objectForKey:@"text"]]];
}
mytextview.text = resultStr;
你的文本视图在哪里?您想将文本视图添加到您的单元格中,还是您已经在其他地方有了文本视图,只想在那里显示此文本?您想在一个UITextView
中显示它吗?@Nekto是,我想在一个文本视图中显示它。@ElanthiraiyanS我的文本视图不在uitableview中,它在tableview之外是一个不同的视图。我想在viewdidload方法中编写mytextview.text=