[英]UITableView showing unexpected rows on iPad (ios7):
它有第一行和第三行,我不想显示。 我发现了相同的问题,但他(她)与我没有相同的问题,我无法解决问题。使用iPad(ios 6)可以正常工作,但此错误发生在iPad(ios7)上。我的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return (calEnabled.boolValue ? 2 : 1);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return 1;
if (calEnabled.boolValue) {
return (reminderEnabled.boolValue ? 2 : 1);
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 || indexPath.row == 0) {
return 44;
}
return 200;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tabView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CallSettingsTableViewCell* sourceCell = [tabView dequeueReusableCellWithIdentifier:@"VMSettingsTabCell_ID"];
if (sourceCell == nil) {
sourceCell = [[CallSettingsTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"VMSettingsTableCell_ID"];
}
if (indexPath.section == 0)
{
sourceCell.textLabel.text = calEnabled.title;
sourceCell.accessoryView = calEnabled.ui_switch;
}
else if (indexPath.row == 0)
{
sourceCell.textLabel.text = reminderEnabled.title;
sourceCell.accessoryView = reminderEnabled.ui_switch;
}
else
{
[sourceCell disableRightSwipe];
sourceCell.textLabel.text = calReminder.title;
sourceCell.accessoryView = calReminder.ui_picker;
}
sourceCell.accessoryType = UITableViewCellAccessoryNone;
sourceCell.selectionStyle = UITableViewCellSelectionStyleNone;
return sourceCell;
}
很高兴帮助我解决它。 预先感谢。
尝试添加以下代码以删除各节之间的空格,或者您可以简单地尝试使用UITableViewStylePlain代替UITableViewStyleGrouped。
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.001;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.001;
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}
改变这个
- (UITableViewCell *)tableView:(UITableView *)tabView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CallSettingsTableViewCell* sourceCell = [tabView dequeueReusableCellWithIdentifier:@"VMSettingsTabCell_ID"];
if (sourceCell == nil) {
sourceCell = [[CallSettingsTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"VMSettingsTableCell_ID"];
}
if (indexPath.row == 0)
{
sourceCell.textLabel.text = calEnabled.title;
sourceCell.accessoryView = calEnabled.ui_switch;
}
else if (indexPath.row == 1)
{
sourceCell.textLabel.text = reminderEnabled.title;
sourceCell.accessoryView = reminderEnabled.ui_switch;
}
else
{
[sourceCell disableRightSwipe];
sourceCell.textLabel.text = calReminder.title;
sourceCell.accessoryView = calReminder.ui_picker;
}
sourceCell.accessoryType = UITableViewCellAccessoryNone;
sourceCell.selectionStyle = UITableViewCellSelectionStyleNone;
return sourceCell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.