gpt4 book ai didi

iphone - 在 iPhone 的 TextView 中显示数组值

转载 作者:行者123 更新时间:2023-11-28 23:12:10 27 4
gpt4 key购买 nike

我有一个名为 bookmark 的数组,它包含值,我将它显示在一个 tableview 单元格中,我知道如何在 tablecell 中显示它。但我希望相同的数组在 textview 中显示它。这是我的 tableview 代码。

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

//自定义表格 View 中的行数。

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

关于iphone - 在 iPhone 的 TextView 中显示数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7912459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com