我试图用一个问题填充我的每个 UITableViewCells,每个问题都在一个 NSArray 中。这些问题比 iPhone 屏幕可以显示的更宽,我无法弄清楚如何显示问题,因此它返回到下一行以显示整个问题。
我最初使用继承了 UITableViewCell 的 CustomCell 类,并尝试将每个问题显示为 textView,但我根本无法显示我的问题。
我的目标是为 UITableView 的每个部分提供 3 行,这些行都将由一个按钮填充,供用户回答每个问题。
这是我必须填充 UITableView 的代码
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [survey.questions count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"MyCustomCell";
/*
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *que = (NSString *)[survey.questions objectAtIndex:indexPath.row];
cell.textLabel.text = que;
cell.textLabel.numberOfLines = 0;
*/
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *que = (NSString *)[survey.questions objectAtIndex:indexPath.row];
NSLog(@"Que Value: %@\n", que);
cell.queLabel.text = que;
cell.queLabel.numberOfLines = 0;
/*
if (numberOfSectionsInTableView.indexPath.section == 1) {
NSLog(@"Button 1");
}
*/
return cell;
}
最佳答案
您可以使用以下命令设置自动换行:
cell.textLabel.numberOfLines = 0;
如果您想向 Storyboard 中的单元格添加按钮,请创建一个新的 .xib
文件并以这种方式布置单元格。
关于ios - 在 UITableViewCell 中为 textLabel 设置边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34188854/