【发布时间】:2015-01-28 06:11:20
【问题描述】:
这里还有其他类似的问题,但没有一个能回答我正在寻找的问题。
我的设置屏幕应该如下所示:
我添加了新的UITableViewCell 类并使用以下代码将其连接到主表:
static NSString *cellIdentifier = @"settingCellIdentifier";
SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SettingsTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
我知道我们将表格样式设置为 UITableViewCellStyleSubtitle 以添加详细文本,但我知道这样做的唯一方法是:
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIdentifier];
在我的情况下,我无法使用此代码。
目前我正在使用两个标签,它带来了以下混乱:
以下是 cellForRowAtIndexPath 代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"settingCellIdentifier";
SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SettingsTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSInteger row = indexPath.row;
switch (row) {
case 0:
cell.settingLabel.text = @"Settings";
cell.subText.text = @"";
break;
case 1:
cell.settingLabel.text = @"Account Info";
cell.subText.text = @"Display your Home Business account information";
break;
case 2:
cell.settingLabel.text = @"Sign Out";
cell.subText.text = @"Signed in as ";
break;
case 3:
cell.settingLabel.text = @"Send Feedback";
cell.subText.text = @"Send comments, requests or error reports to Home Business";
break;
case 4:
cell.settingLabel.text = @"Terms of User";
cell.subText.text = @"";
break;
case 5:
cell.settingLabel.text = @"Privacy Policy";
cell.subText.text = @"Your privacy and security are our top priorities";
break;
case 6:
cell.settingLabel.text = @"Like us on Facebook";
cell.subText.text = @"";
break;
case 7:
cell.settingLabel.text = @"Follow us on Twitter";
cell.subText.text = @"";
break;
case 8:
cell.settingLabel.text = @"About Us";
cell.subText.text = @"";
break;
default:
break;
}
return cell;
}
我需要知道如何添加只有一个标签的详细文本。
【问题讨论】:
-
去自定义表格视图单元格,为什么你有任何特定的需求?
-
在您填充标签的位置显示代码。
-
我使用自定义表格视图单元格。需要知道如何在那里为标签添加详细文本。
-
@FawadMasud: cell.settingLabel.text = @"账户信息"; cell.subText.text = @"显示您的家庭企业帐户信息" in cellForRowAtIndexPath
-
你在使用自动布局吗?如果是这样,您的约束设置是否正确?
标签: ios objective-c iphone xcode